我的CI有两个主要步骤。构建和部署。构建的结果是将一个工件上传到maven nexus.目前,手动部署步骤只是从nexus获取最新的工件并进行部署。
stages:
- build
- deploy
full:
stage: build
image: ubuntu
script:
- // Build and upload to nexus here
deploy:
stage: deploy
script:
- // Take latest artifact from nexus and deploy
when: manual但对我来说,总是部署来自每个管道的最新版本似乎没有太大意义。我认为理想情况下,每个管道的部署步骤应该部署由相同管道构建任务构建的工件。否则,无论何时启动,每个管道的部署步骤都将执行完全相同的操作。
所以我有两个问题。2)如果我仍然想保持“部署最新版本”的功能,那么gitlab是否支持在每个管道中单独添加一个任务,因为正如我所解释的那样,这一步并不会让很多搜索工作处于流水线中?我想象它在一个单独的特定位置。
发布于 2019-12-11 05:38:57
不太熟悉maven和nexus,但是假设您可以在推送之前命名工件,那么可以添加一个内置的环境变量来指定它来自哪个管道。
即:
...
Build:
stage: build
script:
- ./buildAsNormal.sh > build$CI_PIPELINE_ID.extension
- ./pushAsNormal.sh
Deploy:
stage: deploy
script:
- ./deployAsNormal #(but specify the build$CI_PIPELINE_ID.extension file)您可以使用许多非常有用的配置项环境变量。完整的列表是here。$CI_PIPELINE_ID和$CI_JOB_ID的不同之处在于,对于管道中的所有作业,无论它们何时执行,管道id都是恒定的。这意味着即使您在自动步骤后一周运行手动步骤,管道id也是相同的。作业id特定于每个作业。
发布于 2019-12-11 20:27:56
关于你的comment,使用artifacts:可以解决你的问题。
您可以将版本号放在一个文件中,并在下一阶段获取该文件:
stages:
- build
- deploy
full:
stage: build
image: ubuntu
script:
- echo "1.0.0" > version
- // Build and upload to nexus here
artifacts:
paths:
- version
expire_in: 1 week
deploy:
stage: deploy
script:
- VERSION = $(cat version)
- // Take the artifact from nexus using VERSION variable and deploy
when: manual另一种方法是构建,推送到nexus,并使用artifact:将构建的结果传递给Deploy作业:
stages:
- build
- deploy
full:
stage: build
image: ubuntu
script:
- // Build and put the result in out/ directory
- // Upload the result from out/ to nexus
artifacts:
paths:
- out/
expire_in: 1 week
deploy:
stage: deploy
script:
- // Take the artifact from in out/ directory and deploy it
when: manualhttps://stackoverflow.com/questions/59263495
复制相似问题