从 Bitbucket 管道构建 arg 未显示在最终图像中

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

在我的管道文件中,我有以下...

pipelines:
  tags:
    '*.*.*-dev':
      - step:
          name: Build Base Image
          script:
            - echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
            - docker pull ${IMAGE_NAME}:base
            - docker build . --file base.Dockerfile --tag ${IMAGE_NAME}:base --tag ${IMAGE_NAME}:base-${BITBUCKET_TAG} --cache-from ${IMAGE_NAME}:base
            - docker push "${IMAGE_NAME}:base"
            - docker push "${IMAGE_NAME}:base-${BITBUCKET_TAG}"
          services:
            - docker
      - step:
          name: Build Final Image
          script:
            - echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
            - docker build . --file Dockerfile --tag ${IMAGE_NAME}:latest --tag ${IMAGE_NAME}:${BITBUCKET_TAG} --build-arg IMAGE_NAME="${IMAGE_NAME}:base-${BITBUCKET_TAG}" --build-arg BITBUCKET_TAG="${BITBUCKET_TAG}"
            - docker push "${IMAGE_NAME}:latest"
            - docker push "${IMAGE_NAME}:${BITBUCKET_TAG}"
          services:
            - docker

在 dockerfile 中...

ARG IMAGE_NAME
ARG BITBUCKET_TAG
FROM $IMAGE_NAME

...other build stuff

ENV API_REV_VERSION=${BITBUCKET_TAG}

作为参考,IMAGE_NAME 在图像中似乎工作得很好,(但仅适用于上述语法)。

但是,即使我可以确认 BITBUCKET_TAG 不为空,因为它只在它不为空时运行,环境变量在最终图像中显示为 null。 (在 shell 中运行

env
会在自己的行上显示
API_REV_VERSION=

为什么环境变量没有正确设置?

docker bitbucket bitbucket-pipelines
© www.soinside.com 2019 - 2024. All rights reserved.