Custom build steps

This guide covers:

Custom build steps

You can specify custom build scripts to run during different build phases by adding scripts to the repository or using special Nevercode environment files.
If you have added scripts to the repository, Nevercode will automatically detect .sh files which have been named as shown in the table below.

Working directory of all the custom build scripts is the path to the cloned repository. This means that if you need to access some files in your repository, you can use relative paths from the repository root.

Please note that multiple scripts with same name in the repository are not allowed and this will fail your build.

Adding custom build steps

To add a script file:

  1. Navigate to the Environment page in your project settings.
  2. In the Environment Files section click the Add button.
  3. Drag and drop your file to the upload area, or click on it to browse and select from your file directory.
  4. Type the name of your file precisely as shown in the custom build steps table, depending on which build step should run the script.
Naming the custom build script

Naming the custom build script

If you have already uploaded scripts to environment files and also to your repository, then Nevercode will use files specified in the repository.

To delete a script, click the Delete icon on the right for the script you want to delete.

Available custom build steps

In the table below you can see all available build steps. Your custom build script needs to be named exactly as shown below.

Note that we expect the scripts to start with shebang line. Meaning your Bash script should have

#!/bin/sh

as the first line of the script.

Environment file key / Script name
Description

NC_POST_CLONE_SCRIPT

Run the script after the repository is cloned.

NC_PRE_BUILD_SCRIPT

Run the script before the build phase is started.

NC_POST_BUILD_SCRIPT

Run the script after the build phase has finished.

NC_PRE_TEST_SCRIPT

Run the script before the test phase is started.

NC_POST_TEST_SCRIPT

Run the script after the test phase has finished.

NC_PRE_PUBLISH_SCRIPT

Run the script before the publishing phase is started.

NC_POST_PUBLISH_SCRIPT

Run the script after the publishing phase has finished.

Example use case

Let's assume that to successfully build your application various dependencies need to be installed first or some scripts have to be executed beforehand.

  1. Write a pre-build script (example below).
  2. Upload the script in the Environment Files section.
  3. Name the corresponding environment variable to NC_PRE_BUILD_SCRIPT.
#!/bin/sh

set -e	# exit on first failed command
set -x  # print all executed commands to the terminal

# $NEVERCODE_BUILD_DIR points to the cloned repository root

# suppose you have PHP code in repo_root/php and there is also composer.json
# then you can install dependencies with composer like
cd $NEVERCODE_BUILD_DIR/php
composer install
# then run your PHP script with
php $NEVERCODE_BUILD_DIR/php/my_script.php

# install Python (version 2.7) requirements using pip
sudo pip install requests
sudo pip install -r $NEVERCODE_BUILD_DIR/python/requirements.txt
# run Python (version 2.7) scripts
python $NEVERCODE_BUILD_DIR/python/my_script.py

# for JavaScript you can use npm
npm install whateveryoulike.js
# execute the JavaScript scripts with node
node $NEVERCODE_BUILD_DIR/js/my_script.js

# need something else? install it with Homebrew
brew install needed-package-here