dockerbitbucket-pipelines

Push To Docker Hub from Bitbucket Pipeline


I have a bitbucket-pipelines.yml file with the code below

image: atlassian/default-image:2

pipelines:
  branches:
    master:
      - step:
          name:
            Build And Publish To Azure
          services:
            - docker
          script:
            #Authenticate on Azure
            - docker login -u $AZURE_USER -p $AZURE_PASS myticket.azurecr.io
            #Build Docker Image
            - docker build -t myticket.azurecr.io/myticket .
            #Push to Azure
            - docker push myticket.azurecr.io/myticket
      - step:
          name: 
            Push To Docker Hub
          services:
            - docker
          script:
            - docker logout
            #Authenticate on Docker
            #The below says Error: Cannot perform an interactive login from a non TTY device
            - docker login --username $DOCKER_HUB_USERNAME --password-stdin $DOCKER_HUB_PASSWORD
            #The below says invalid username or password
            # - echo $DOCKER_HUB_PASSWORD | docker login --username $DOCKER_HUB_USERNAME --password-stdin
            #Build Docker Image
            - docker build -t myticket.azurecr.io/myticket .
            #Push to Docker Hub
            - docker push isaachats/myticket:latest

I have added comments with the errors I am getting, What am I missing? I also tried adding hub.docker.com to the login line in step two but still failed. What am I doing wrong?


Solution

  • Either

    docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_PASSWORD"
    

    or

    echo "$DOCKERHUB_PASSWORD" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
    

    should work just fine.

    If you are seeing "invalid username or password" error messages, check those credentials again, they are most probably wrong. Rotating the token you are using should cut it.