GoCD trigger-with-options WorkAround

vijay chandamala
2 min readMar 5, 2021

--

My first ever CI/CD tool was GoCD by thoughtworks™ . The way it was configured, it just runs a set of fixed commands for different Git commits.

There was always a question if we could click on trigger with options select a parameter that can get passed to the command that’s being run which would solve a lot of issues that we had.

Unfortunately trigger with options only shows different versions of the materials from which you can pick a commit/version.

TLDR;

Example :

Let’s say I have a task for which I should be able to select an argument from a list while triggering with options.

command : make A=(variable argument) ENV=qa

possible arguments : template/install/uninstall/upgrade/upstall

Now here’s what we can do :

  • Create a git repo with a file named make-arg.txt whose content is template and add it as a material to a pipeline along with the source code repo. (make sure the commit message indicates the content of the file)
  • Now trigger the pipeline so that it can build a commit version in the pipeline material containing text template.
  • Update the make-arg.txt content to install in git and commit again with relevant commit message denoting the file content.
  • Trigger the pipeline again so that it creates a new commit in the material.
  • Repeat the same for different arguments mentioned above.
smart AF XD

Done! if you goto trigger with options now, you’ll have the make-arg repo with five different commits one for each of template/install/uninstall/upgrade/upstall .

Now within your task , which is

make A=(variable argument) ENV=qa

try to pass the content of the file make-arg.txt as parameter by doing a cat of it

Example: make A=$(cat MATERIAL_DIR/make-arg.txt) ENV=qa

which when selected particular commit will perform that action.

Cons only

There are short-comings to this, for example :

  • you cannot use it with automatic build triggers where it will select latest commit (which can be fixed by having a default value in the latest commit)
  • argument will remain same for all the stages within a multi-stage pipeline. could cause issues when you want to change it for each stage within the pipeline.

--

--