从另一个步骤上传构建的工件

问题描述 投票:0回答:1

我对我的 bitbucket 管道有疑问。我已经设置了所有变量,但无法将构建的 docker 映像复制到下一个管道步骤中的另一个位置。

 preview:
      - step:
          name: Build Docker image for preview branch and save as .tar
          caches:
            - docker
          size: 2x #2x memory flag
          services:
            - docker
          script:
            - echo "Building Docker image for preview branch..."
            - docker build -f ./src/API/Dockerfile -t $BITBUCKET_REPO_SLUG .
            - docker save -o $BITBUCKET_REPO_SLUG.tar $BITBUCKET_REPO_SLUG
      - step:
          name: Upload Docker image as artifact
          script:
            - pipe: atlassian/bitbucket-upload-file:0.7.1
              variables:
                BITBUCKET_USERNAME: $BITBUCKET_USERNAME
                BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
                FILENAME: "$BITBUCKET_REPO_SLUG.tar"
                DIRECTORY: "downloads"

它会产生以下错误:

Status: Downloaded newer image for bitbucketpipelines/bitbucket-upload-file:0.7.1
INFO: Executing the pipe...
✖ File Application.tar doesn't exist.

(docker构建成功)

如何将生成的 docker 构建的 .tar 文件复制到新位置?

bitbucket-pipelines
1个回答
0
投票

应从前一步骤复制到后续步骤的工件必须使用

artifacts
键声明。

以你的例子:

pipelines:
  branches:
    preview:
      - step:
          name: Build Docker image for preview branch and save as .tar
          caches:
            - docker
          services:
            - docker
          script:
            - echo "Building Docker image for preview branch..."
            - docker build -f ./src/API/Dockerfile -t $BITBUCKET_REPO_SLUG .
            - docker save -o dockerimage.tar $BITBUCKET_REPO_SLUG
          artifacts:
            - dockerimage.tar
      - step:
          name: Upload Docker image as artifact
          script:
            - pipe: atlassian/bitbucket-upload-file:0.7.1
              variables:
                BITBUCKET_USERNAME: $BITBUCKET_USERNAME
                BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
                FILENAME: dockerimage.tar
                DIRECTORY: "downloads"

您将无法在其中插入变量,因此您应该采用硬名称或将所有图像放入子文件夹中(然后声明

artifacts: ["build/*.tar"]
等)

© www.soinside.com 2019 - 2024. All rights reserved.