仅当上游管道中的工件不可用时,我才尝试触发下游管道。我正在使用 Gitlab CE v13.5.1。
这个想法是:
预构建阶段:从 nexus 卷曲并检查工件是否可用。如果是,请不要运行下游触发器,否则运行它。
- 为了实现这一点,当 curl 失败时,我正在创建一个虚拟 exists.txt 文件,然后在后期阶段在存在条件下使用该文件。
仅当存在 exists.txt 时运行触发器。但是,问题是无论存在与否,触发器都会一直运行。也就是说,触发阶段的存在条件不起作用。
以下是 gitlab-ci 文件:
image: ${NEXUS_REPO_DOCKER_URL}/<<image>>
variables:
CUSTOMER_NAME: "ABC"
CONFIG_VERSION: "1.2.7"
PICKER_TEMPLATE_TAG: "6.9.15"
stages:
- prebuild
- trigger
- build
- release
checkArtifactAvailability:
stage: prebuild
only:
- master
tags:
- docker
- lxc
script:
- set +e
- curl -s -S -f $NEXUS_RAW_PICKER_REPOSITORY/${PRODUCT_FLAVOR}/${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk --output ${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk
- "if [ '$?' -gt '0' ]; then touch exists.txt; fi"
-set -e
artifacts:
expire_in: 1 hour
paths:
- ${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk
- exists.txt
createApk:
stage: trigger
rules:
- exists:
- exists.txt
trigger:
project: dev/<<project_name>>
strategy: depend
when: on_failure
buildZip:
stage: build
tags:
- docker
- lxc
rules:
- exists:
- exists.txt
script:
- curl -s -S -f $NEXUS_RAW_PICKER_REPOSITORY/${PRODUCT_FLAVOR}/${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk --output ${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk
- zip -r v${CONFIG_VERSION}.zip <<files>> ${PRODUCT_FLAVOR}-${BUILD_TYPE}v${PICKER_TEMPLATE_TAG}.apk
artifacts:
expire_in: 1 hour
paths:
- v${CONFIG_VERSION}.zip
releaseToNexus:
stage: release
tags:
- docker
- lxc
rules:
- exists:
- exists.txt
needs:
- job: buildZip
artifacts: true
script:
- curl -u $NEXUS_USER:$NEXUS_PASSWORD --upload-file ./v${CONFIG_VERSION}.zip $NEXUS_RAW_QA_REPOSITORY/Picker/${CUSTOMER_NAME}/