GitLab:如何包含上一个作业';将工件作为发布资产?
任务GitLab:如何包含上一个作业';将工件作为发布资产?,gitlab,continuous-integration,gitlab-ci,continuous-deployment,Gitlab,Continuous Integration,Gitlab Ci,Continuous Deployment,任务create:release创建一个新版本。如何在taskcreate: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"
create:release
创建一个新版本。如何在taskcreate: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
job中,将作业id保存在环境文件中,该文件应位于该作业的artifacts.reports.env
中。稍后,在create:release
作业中,使用API“https://gitlab.com///-/jobs//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"
准备:发布:
阶段:准备发布
在脚本之前:
-echo“为构建设置包”
-apk—无缓存添加压缩
脚本:
-回应“准备发布”
-回声“构建核心”
-纱线--cwd/芯线/安装和纱线--cwd/芯线/构建
-echo“核心的Zip分发文件夹”
-zip-r core.zip./core/dist./core/node_modules./core/package.json
在脚本之后:
-echo“JOB\u ID=$CI\u JOB\u ID”>>JOB.env
人工产品:
路径:
-core.zip
永远不会
报告:
dotenv:job.env
创建:发布:
阶段:发布
图片:registry.gitlab.com/gitlab org/release cli:latest
需要:
-工作:准备:发布
文物:真的
变量:
标签:“$CI_COMMIT_SHA”
脚本:
-echo“创建发行版$TAG”
-echo$JOB\u ID
发布:
名称:'Release$TAG'
标签名称:“$tag”
参考:“$TAG”
描述:'Release$TAG'
资产:
链接:
-名称:“core.zip”
url:“https://gitlab.com///-/jobs//artifacts/download"
假设release
阶段在prepare\u release
阶段之后,则create:release
作业应自动从prepare:release
作业访问工件。尝试对create:release
作业执行ls-la
命令script@Lukman这是正确的。问题是如何将它们包含为发布资产?链接之后,每个资源都有属性URL和文件路径。在这种情况下,当资产是作业工件时,它们的值是什么?