I am trying to implement the following functionality in Gitlab CI. I would like to execute a job whenever BOTH conditions are true:
- A merge request is made to the master branch
- A git commit tag is present.
Again, I would like to run the job only if BOTH conditions are met.
In the past, this could be accomplished by using the only and except keywords. As these are deprecated for some time now, I would like to implement the functionality using the rules and if keywords/statements.
My first attempt looks like this:
job1: script: - echo "Do some stuff ..." rules: - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" && $CI_COMMIT_TAG != ""' However, that doesn't seem to work for reasons I can't fathom. Can anyone help me with this?
In this context, I also wondered if maybe the rounding of the two conditions is causing the problem and if it might be more appropriate to specify the conditions in multiple if statements like so:
job1: script: - echo "Do some stuff ..." rules: - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' - if: '$CI_COMMIT_TAG != ""' A corresponding Google search did not bring me closer to a solution. I could not find anything on the topic of multiple if statements. Maybe someone else knows more?
Any help in this matter would be greatly appreciated.
If an if statement is true, add the job to the pipelineSo you definitely don't want to separate your condition else the job will be added it either is true. Your first try looks ok but your are not describing "doesn't seem to work" with enough details. Which debugging steps did you take ?$CI_COMMIT_TAGvariable doesn't contain anything when creating a merge request to the master branch (using merge pipelines). It's simply empty, thats why any job with that condition is never going to run. I have no idea how to get around this though. I seems fairly common to me that one wants to create a new release whenever I merge the develop into the master with a new version number as git tag? Why is this so hard?