Different Build Scripts for different Commits in Gitlab Ci

Using GitLab Continuous Integration is pretty cool for testing. You just need to edit the build script under Build settings and can run your tests. For example PHPUnit tests. Your tests will run and you will see if you get a success or a fail. All fine.


Changing the Build Script

But what should you do if you want to add Behat tests. You will create a branch create_behat_tests for example. And you will create your first behat test. Now should you add the command for Behat to your build script. And it could look like this for example.

php bin/phpunit
php bin/behat
The big problem of this global build script is, your master doesn't know a script bin/behat. And your master branch will fail.

Put the build script into git

The solution is pretty easy. Just put a script into your git repository and just call this script via build script in Gitlab Ci. It can change with every commit. It's the same like the travis.yml for Travis. But the cool thing on Gitlab Ci is, you don't have to put such a file into your repository. I guess the inventors of Gitlab Ci never wanted to determine the existence of such a file in your repository. It's up to you.

The example from above

In the example above, I just updated my build script in Gitlab Ci. And I have put gitlab_ci.sh into the root of my repository.


In the master the file looks like this.

php bin/phpunit
And in my branch create_behat_tests, it looks like this.
php bin/phpunit
php bin/behat

Next Previous