此问题适用于Bitbucket管道 . 我已经看到了其他相关问题,坦率地说,Bitbucket yaml和Dockerfile脚本在bash终端中直接执行时效果很好 .

就在执行管道时,它在成功登录后立即失败 .

这是我的Yaml文件:

# enable Docker for the repository
options:
  docker: true

# Start the pipeline
pipelines:
  default:
    - step:
        script: # Name the image and create a docker image
          - docker build -t "my_docker_id/my_app:latest" . 
          - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
          - docker push my_docker_id/my_app:latest

我的Dockerfile看起来像:

FROM ubuntu:latest

# Install Python and related tools
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get -y upgrade
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN pip3 install --upgrade pip

# Now use Pip to install Flask
RUN pip3 install flask

# Set the working directory to Ubuntu user home
WORKDIR /home/ubuntu

# Then copy the website folder to home folder
COPY . /home/ubuntu

docker登录成功:

docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD<1s
Login Succeeded

管道失败:

docker push my_docker_id/my_app:latest

失败:

+ docker push cbrodock/corpsite:latest The push refers to a repository [docker.io/cbrodock/corpsite] bdca855fbe4a: Preparing d147d767df7b: Preparing f6aad432f761: Preparing 0da658ad5264: Preparing 84e11e4ededf: Preparing 50fd25888dad: Preparing 2cb0a11f65e0: Preparing ad8ba289abb4: Preparing 33f1a94ed7fc: Preparing b27287a6dbce: Preparing 47c2386f248c: Preparing 2be95f0d8a0c: Preparing 2df9b8def18a: Preparing 50fd25888dad: Waiting 47c2386f248c: Waiting 2cb0a11f65e0: Waiting 33f1a94ed7fc: Waiting 2df9b8def18a: Waiting b27287a6dbce: Waiting 2be95f0d8a0c: Waiting ad8ba289abb4: Waiting unauthorized: authentication required

如果我在MacOS上的bash终端中执行相同的步骤,它们会执行正常并推送成功 .

有任何想法吗?