首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在成功的管道上发布

在成功的管道上发布
EN

Stack Overflow用户
提问于 2022-08-27 14:13:17
回答 1查看 22关注 0票数 0

我使用一个私有的gitlab-runner来构建一个ISO,然后将这个ISO及其日志上传到我的S3桶中。这部分管道的工作没有任何问题,但我最近决定在一个成功的管道上创建“释放”。由于这个原因,我使用以下.gitlab-ci.yml

代码语言:javascript
复制
stages:
  - build
  - release

build_amd64:
  stage: build

  # Do not run the pipeline if the following files/directories are modified:
  # except:
  #   changes:
  #     - Pictures/
  #     - .gitignore
  #     - FUNDING.yml
  #     - LICENSE
  #     - README.md

  tags:
    - digitalocean

  timeout: 4 hours

  before_script:
    # Make sure the dependencies for the build are up-to-date:
    - /usr/bin/apt update
    - /usr/bin/apt install --only-upgrade -y curl git live-build cdebootstrap

    # Save Job ID
    - echo 'Saving $CI_JOB_ID to .env'
    - echo BUILD_JOB_ID=$CI_JOB_ID >> .env

  script:
    # Build the ISO:
    - ./build.sh --arch amd64 --variant i3_gaps --verbose

  after_script:
    - |
      if [ $CI_JOB_STATUS == 'success' ]; then
        # Remove everything except the "images" folder:
        shopt -s extglob 
        /usr/bin/rm -rf !(images/)

        # Upload log:
        # /usr/bin/s3cmd put ./images/log s3://$S3_BUCKET/download/log
        
        # Set log access to public:
        # /usr/bin/s3cmd setacl s3://$S3_BUCKET/download/log --acl-public

        # Upload iso:
        # /usr/bin/s3cmd put ./images/iso s3://$S3_BUCKET/download/iso
        
        # Set iso access to public:
        # /usr/bin/s3cmd setacl s3://$S3_BUCKET/download/iso --acl-public

      else
        # If pipeline fails, skip the upload process:
        echo 'Skipping upload process due to job failure'

        sleep 5; /usr/sbin/reboot
        /usr/bin/screen -dm /bin/sh -c '/usr/bin/sleep 5; /usr/sbin/reboot;'

      fi

  artifacts:
    reports:
      # Ensure that we have access to .env in the next stage
      dotenv: .env

publish_release:
  image: registry.gitlab.com/gitlab-org/release-cli:latest

  stage: release
  
  needs:
    - job: build_amd64
      artifacts: true
 
  release:
    name: 'ISO | $CI_COMMIT_SHORT_SHA | $BUILD_JOB_ID'

    description: "Created and released via Gitlab CI/CD."
    
    tag_name: "$CI_COMMIT_SHORT_SHA"

    ref: '$CI_COMMIT_SHA'
    
    assets:
      links:
        - name: "ISO"
          url: "https://foo.bar"
          link_type: "image"
        
        - name: "Build Log"
          URL: "https://foo.bar"
          link_type: "other"

但是,我已经意识到,当release作业运行时,它会在没有任何问题的情况下创建发行版,然后使用新标记(在本例中是$CI_COMMIT_SHORT_SHA)创建一个新管道,而不是最初用这个标记创建这个新管道,而不是创建main分支。

我检查了文件,但找不到关于这件事的任何东西。

发布发行版时,是否有一种不运行管道的方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-27 17:19:39

这里发生的事情是,由于指定的标记不存在,所以它将与发行版一起创建。这会导致被标记的管道运行(就像您创建了标记并推送它一样)。

如果您只想忽略标记管道,可以使用工作流规则来排除它们:

代码语言:javascript
复制
workflow:
  rules:
    - if: $CI_COMMIT_TAG
      when: never  # ignore pipelines for tags
    - when: always # run the pipeline otherwise
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73511719

复制
相关文章

相似问题

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