簡體   English   中英

在成功的管道上發布版本

[英]Publish release upon successful pipeline

我正在使用私有gitlab-runner構建 ISO,然后將 ISO 及其日志上傳到我的 S3 存儲桶。 管道的這一部分工作順利,但我最近決定在成功的管道上創建“發布”。 出於這個原因,我使用以下.gitlab-ci.yml

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分支。

我檢查了文檔,但我找不到有關此問題的任何信息。

有沒有辦法在發布版本時不運行管道?

這里發生的情況是,由於指定的標簽不存在,它將隨發行版一起創建。 這會導致帶標簽的管道運行(就像您創建標簽並推送它一樣)。

如果您只想忽略標簽管道,可以使用工作流規則來排除它們:

workflow:
  rules:
    - if: $CI_COMMIT_TAG
      when: never  # ignore pipelines for tags
    - when: always # run the pipeline otherwise

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM