首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用gitlab部署某个构建

使用gitlab部署某个构建
EN

Stack Overflow用户
提问于 2019-12-10 17:00:16
回答 2查看 118关注 0票数 0

我的CI有两个主要步骤。构建和部署。构建的结果是将一个工件上传到maven nexus.目前,手动部署步骤只是从nexus获取最新的工件并进行部署。

代码语言:javascript
复制
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是否支持在每个管道中单独添加一个任务,因为正如我所解释的那样,这一步并不会让很多搜索工作处于流水线中?我想象它在一个单独的特定位置。

EN

回答 2

Stack Overflow用户

发布于 2019-12-11 05:38:57

不太熟悉maven和nexus,但是假设您可以在推送之前命名工件,那么可以添加一个内置的环境变量来指定它来自哪个管道。

即:

代码语言:javascript
复制
...
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特定于每个作业。

票数 0
EN

Stack Overflow用户

发布于 2019-12-11 20:27:56

关于你的comment,使用artifacts:可以解决你的问题。

您可以将版本号放在一个文件中,并在下一阶段获取该文件:

代码语言:javascript
复制
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作业:

代码语言:javascript
复制
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: manual
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59263495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档