My team has a pipeline that is run whenever we tag a commit. The tags come in a couple different formats (for example, we have different tags for releases versus release candidates) and some of the steps in the pipeline only need to run for certain types of tags. Currently, we’re using
if conditionals with regular expressions to specify if a given step should run for a given tag.
Everything is working fine, but as we’ve added more steps we’ve had to copy-paste the same regular expressions into different steps so we thought it would be cleaner if we could define the regular expressions once as environment variables and then reference them in the
if conditionals. It seems that the conditional parser doesn’t support this use case though as the type returned by the
build.env function is a string but the parser is expecting a regular expression. So even though the value of the environment variable may be a valid regular expression, the parser doesn’t recognize it as such.
The following toy pipeline demonstrates the problem we’re running into.
env: ENV_REGEX: "/^foo\$/" steps: - label: "Testing Regular Expressions: Env Var" if: 'build.env("ENV_KEY") =~ build.env("ENV_REGEX")' command: echo "env var" - label: "Testing Regular Expressions: Static" if: 'build.env("ENV_KEY") =~ /^foo\$/' command: echo "static"
The second step works fine and is the current approach we’re following, but becomes a little cumbersome if we want to refer to the same regular expression in multiple steps. The first step is considered invalid though and the following error is returned:
One of the steps you provided was invalid: Error parsing
ifexpression: Unexpected type: expected regular expression but