GitLab:如何将以前工作的工件作为发布资产包含在内?
GitLab: How to include the previous job's artifacts as release assets?
任务create:release
创建了一个新版本。我们如何在任务 create:release
中添加工件 core.zip
?
prepare:release:
stage: prepare_release
before_script:
- echo "Setting up packages for Build"
- apk --no-cache add zip
script:
- echo "Preparing release"
- echo "Build Core"
- yarn --cwd ./core/ install && yarn --cwd ./core/ build
- echo "Zip distribution folder for Core"
- zip -r core.zip ./core/dist ./core/node_modules ./core/package.json
artifacts:
paths:
- core.zip
expire_in: never
create:release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: prepare:release
artifacts: true
variables:
TAG: '$CI_COMMIT_SHA'
script:
- echo "Create Release $TAG"
release:
name: 'Release $TAG'
tag_name: '$TAG'
ref: '$TAG'
description: 'Release $TAG'
我已经解决了这个问题。在 prepare:release
作业中,将作业 ID 保存在环境文件中,此文件应位于此作业的 artifacts.reports.env
中。之后在create:release
作业中,使用API"https://gitlab.com/<namespace>/<project_name>/-/jobs/<job_id>/artifacts/download"
引用神器
更新管道:
prepare:release:
stage: prepare_release
before_script:
- echo "Setting up packages for Build"
- apk --no-cache add zip
script:
- echo "Preparing release"
- echo "Build Core"
- yarn --cwd ./core/ install && yarn --cwd ./core/ build
- echo "Zip distribution folder for Core"
- zip -r core.zip ./core/dist ./core/node_modules ./core/package.json
after_script:
- echo "JOB_ID=$CI_JOB_ID" >> job.env
artifacts:
paths:
- core.zip
expire_in: never
reports:
dotenv: job.env
create:release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: prepare:release
artifacts: true
variables:
TAG: '$CI_COMMIT_SHA'
script:
- echo "Create Release $TAG"
- echo $JOB_ID
release:
name: 'Release $TAG'
tag_name: '$TAG'
ref: '$TAG'
description: 'Release $TAG'
assets:
links:
- name: "core.zip"
url: "https://gitlab.com/<namespace>/<project_name>/-/jobs/<job_id>/artifacts/download"
我无法使用 gitlab-ci relase cli 的关键字,所以我使用了 release cli shell 脚本,我解决了如下问题:
create_tag:
image: registry.gitlab.com/gitlab-org/release-cli:latest
when: manual
stage: create_tag
# before_script:
# - curl -L --output /usr/local/bin/release-cli "https://release-cli-downloads.s3.amazonaws.com/latest/release-cli-linux-amd64"
# - sudo chmod +x /usr/local/bin/release-cli
# - release-cli -v
script:
- ANGULAR_VERSION=$(node -p "require('./package.json').version")
- echo running release_job for $ANGULAR_VERSION
- export GODEBUG="x509ignoreCN=0"
- docker save -o nmsclientwebangularV$ANGULAR_VERSION.tar $NEXUS_URL/admin/nmsclientwebangular:V$ANGULAR_VERSION
- echo $CI_JOB_ID
- release-cli --insecure-https create --name="Release V$ANGULAR_VERSION" --tag-name="V$ANGULAR_VERSION" --assets-link='{"name":"DockerFile","url":"https://gitlab.sinacomsys.local:9191/nms/Access/NMSClient/nmsclient_web_angular/-/jobs/'$CI_JOB_ID'/artifacts/download?file_type=archive"}'
artifacts:
paths:
- nmsclientwebangular*.tar
only:
- master
在脚本部分的最后一行,我使用 release cli shell 命令创建了 release 标签,我使用了这个 job.be 的 CI_JOB_ID 小心像这样使用它 '$CI_JOB_ID';
如果您想使用另一个作业工件,您应该将该作业 CI_JOB_ID 保存在自定义变量中,如下所示:
export JOB_ID=$CI_JOB_ID
然后使用JOB_ID代替CI_JOB_ID
任务create:release
创建了一个新版本。我们如何在任务 create:release
中添加工件 core.zip
?
prepare:release:
stage: prepare_release
before_script:
- echo "Setting up packages for Build"
- apk --no-cache add zip
script:
- echo "Preparing release"
- echo "Build Core"
- yarn --cwd ./core/ install && yarn --cwd ./core/ build
- echo "Zip distribution folder for Core"
- zip -r core.zip ./core/dist ./core/node_modules ./core/package.json
artifacts:
paths:
- core.zip
expire_in: never
create:release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: prepare:release
artifacts: true
variables:
TAG: '$CI_COMMIT_SHA'
script:
- echo "Create Release $TAG"
release:
name: 'Release $TAG'
tag_name: '$TAG'
ref: '$TAG'
description: 'Release $TAG'
我已经解决了这个问题。在 prepare:release
作业中,将作业 ID 保存在环境文件中,此文件应位于此作业的 artifacts.reports.env
中。之后在create:release
作业中,使用API"https://gitlab.com/<namespace>/<project_name>/-/jobs/<job_id>/artifacts/download"
引用神器
更新管道:
prepare:release:
stage: prepare_release
before_script:
- echo "Setting up packages for Build"
- apk --no-cache add zip
script:
- echo "Preparing release"
- echo "Build Core"
- yarn --cwd ./core/ install && yarn --cwd ./core/ build
- echo "Zip distribution folder for Core"
- zip -r core.zip ./core/dist ./core/node_modules ./core/package.json
after_script:
- echo "JOB_ID=$CI_JOB_ID" >> job.env
artifacts:
paths:
- core.zip
expire_in: never
reports:
dotenv: job.env
create:release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: prepare:release
artifacts: true
variables:
TAG: '$CI_COMMIT_SHA'
script:
- echo "Create Release $TAG"
- echo $JOB_ID
release:
name: 'Release $TAG'
tag_name: '$TAG'
ref: '$TAG'
description: 'Release $TAG'
assets:
links:
- name: "core.zip"
url: "https://gitlab.com/<namespace>/<project_name>/-/jobs/<job_id>/artifacts/download"
我无法使用 gitlab-ci relase cli 的关键字,所以我使用了 release cli shell 脚本,我解决了如下问题:
create_tag:
image: registry.gitlab.com/gitlab-org/release-cli:latest
when: manual
stage: create_tag
# before_script:
# - curl -L --output /usr/local/bin/release-cli "https://release-cli-downloads.s3.amazonaws.com/latest/release-cli-linux-amd64"
# - sudo chmod +x /usr/local/bin/release-cli
# - release-cli -v
script:
- ANGULAR_VERSION=$(node -p "require('./package.json').version")
- echo running release_job for $ANGULAR_VERSION
- export GODEBUG="x509ignoreCN=0"
- docker save -o nmsclientwebangularV$ANGULAR_VERSION.tar $NEXUS_URL/admin/nmsclientwebangular:V$ANGULAR_VERSION
- echo $CI_JOB_ID
- release-cli --insecure-https create --name="Release V$ANGULAR_VERSION" --tag-name="V$ANGULAR_VERSION" --assets-link='{"name":"DockerFile","url":"https://gitlab.sinacomsys.local:9191/nms/Access/NMSClient/nmsclient_web_angular/-/jobs/'$CI_JOB_ID'/artifacts/download?file_type=archive"}'
artifacts:
paths:
- nmsclientwebangular*.tar
only:
- master
在脚本部分的最后一行,我使用 release cli shell 命令创建了 release 标签,我使用了这个 job.be 的 CI_JOB_ID 小心像这样使用它 '$CI_JOB_ID';
如果您想使用另一个作业工件,您应该将该作业 CI_JOB_ID 保存在自定义变量中,如下所示:
export JOB_ID=$CI_JOB_ID
然后使用JOB_ID代替CI_JOB_ID