Reputation: 437
I have a gitlab rule condition like below.
'$ACTION && $REGION && $ROLE_ARN && $PACKAGEURL && $ACTION == "new" && $CLOUD_PLATFORM == "aws" && $ROLE_ARN != "" && $PACKAGEURL != "" && $REGION != ""'
Want to modify it a bit so that, it should check either the existence of PACKAGEURL or BUILDRPMREQUIRED above.
Tried keeping as below but getting run even if the PACKAGEURL or BUILDRPMREQUIRED not provided.
'$ACTION && $REGION && $ROLE_ARN && ($PACKAGEURL || $BUILDRPMREQUIRED) && $ACTION == "new" && $CLOUD_PLATFORM == "aws" && $ROLE_ARN != "" && ($PACKAGEURL != "" || $BUILDRPMREQUIRED != "") && $REGION != ""'
I kept in rule as below.
.ifawsfulldeploy:
rules:
- if: '$ADMIN_SERVER_IP && $ADMIN_SERVER_IP != ""'
when: never
- if: '$ACTION && $REGION && $ROLE_ARN && ($PACKAGE_URL || $BUILDRPMREQUIRED) && $ACTION == "new" && $CLOUD_PLATFORM == "aws" && $ROLE_ARN != "" && ($PACKAGE_URL != "" || $BUILDRPMREQUIRED != "") && $REGION != ""'
when: always
Other rules should be there, with only variables I am getting syntax error.
.ifawsfulldeploy:
rules:
- if: '$ADMIN_SERVER_IP && $ADMIN_SERVER_IP != ""'
when: never
- if: '$ACTION && $REGION && $ROLE_ARN && ( $PACKAGE_URL || $BUILDRPMREQUIRED ) && $ACTION == "new" && $CLOUD_PLATFORM == "aws" && $ROLE_ARN != "" && ( $PACKAGE_URL != "" || $BUILDRPMREQUIRED != "" ) && $REGION != ""'
when: always
And in my job.
only:
variables:
- $PACKAGE_URL
- $BUILDRPMREQUIRED
extends:
- .ifawsfulldeploy
Upvotes: 7
Views: 25511
Reputation: 194
You can check variable is not null or check for at least one character in the variable
rules:
- if: ( $MY_VARIABLE != null || $MY_VARIABLE =~ /^./ )
Upvotes: 0
Reputation: 81
im new in Gitlab but i had the same question and
$FOO != null
condition helped me. Hope it helped u too!
Upvotes: 8
Reputation: 31
Have you tried using a rule just for the variables? Like this example from the Gitlab docs:
job1:
script:
- echo This rule uses parentheses.
only:
variables:
- ($CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "develop") && $MY_VARIABLE
Source: https://docs.gitlab.com/ee/ci/jobs/job_control.html#only-variables--except-variables-examples
Upvotes: 3