一千萬個為什麽

搜索

如何避免bitbucket-pipeline中的代碼重復?



已創建以下bitbucket-pipelines文件:

options:
  docker: true

pipelines:
  default:
    - step:
        script:
          - echo "Login to the docker registry"
          - docker login some-docker-registry
    - step:
        script:
          - echo "Build some-image"
          - docker build some-docker-registry/some-image .
          - docker push some-docker-registry/some-image
    - step:
        script:
          - echo "Build some-image2"
          - docker build some-docker-registry/some-image2 .
          - docker push some-docker-registry/some-image2
        deployment: production

當它由bitbucket運行時,它表示對docker註冊表的身份驗證失敗,所以現在必須一遍又一遍地添加此步驟:

options:
  docker: true

pipelines:
  default:
    - step:
        script:
          - echo "Login to the docker registry"
          - docker login some-docker-registry
          - echo "Build some-image"
          - docker build some-docker-registry/some-image .
          - docker push some-docker-registry/some-image
    - step:
        script:
          - echo "Login to the docker registry"
          - docker login some-docker-registry
          - echo "Build some-image2"
          - docker build some-docker-registry/some-image2 .
          - docker push some-docker-registry/some-image2
        deployment: production

是否可以防止這種重復?已嘗試(請參閱第一個代碼段),但這似乎不起作用,即每個步驟都需要一個docker登錄。

轉載註明原文: 如何避免bitbucket-pipeline中的代碼重復?

一共有 1 個回答:

與Jenkins中的聲明性管道不同,bitbucket似乎沒有這樣的功能。為了防止代碼重復,創建了一個腳本,當前的bitbucket-pipelines看起來如下:

options:
  docker: true

pipelines:
  default:
    - step:
        script:
          - ./build-script.sh API true true
    - step:
        script:
          - ./build-script.sh Write true true
        deployment: production