【发布时间】:2022-12-16 06:14:54
【问题描述】:
当用另一个空变量的内容声明时,如何检查 Gitlab 管道中的空变量?就像下面NO_VAR为空时的变量VAR_NULL:
variables:
VAR_EMPTY: ""
VAR_NULL: "${NO_VAR}"
检查管道结果,其中只有 VAR_EMPTY == "" 和 NO_VAR == null 评估为真的所有其他人都是错误的.
流水线结果(为方便起见截图,完整结果:https://gitlab.com/labaz/test-gitlab-pipeline-null-var/-/pipelines/493036820):
完整的流水线脚本(https://gitlab.com/labaz/test-gitlab-pipeline-null-var/-/blob/main/.gitlab-ci.yml):
variables:
VAR_EMPTY: ""
VAR_NULL: "${NO_VAR}"
jobTest-Var_Empty-IsNull: # This job runs in the build stage, which runs first.
rules:
- if: '$VAR_EMPTY == null'
script:
- 'echo "VAR_EMPTY IS null"'
jobTest-Var_Empty-IsEmpty: # This job runs in the build stage, which runs first.
rules:
- if: '$VAR_EMPTY == ""'
script:
- 'echo "VAR_EMPTY IS \"\""'
jobTest-Var_Null-IsNull: # This job runs in the build stage, which runs first.
rules:
- if: '$VAR_NULL == null'
script:
- 'echo "VAR_NULL IS null"'
jobTest-Var_Null-IsEmpty: # This job runs in the build stage, which runs first.
rules:
- if: '$VAR_NULL == ""'
script:
- 'echo "VAR_NULL IS Empty"'
jobTest-No_Var-IsNull: # This job runs in the build stage, which runs first.
rules:
- if: '$NO_VAR == null'
script:
- 'echo "NO_VAR IS null"'
jobTest_No_Var-IsEmpty: # This job runs in the build stage, which runs first.
rules:
- if: '$NO_VAR == ""'
script:
- 'echo "NO_VAR IS Empty"'
【问题讨论】:
标签: gitlab