0

In the azure pipeline yaml files, the variable imgRepoName is trimmed from the gitRepoName. An bash echo for gitRepoName shown core/cqb-api; bash echo for imgRepoName shown cqb-api

variables:
  vmImageName: 'ubuntu-18.04'
  gitRepoName: $(Build.Repository.Name)
  imgRepoName: $(basename $(gitRepoName))

  - job: build_push_image
    pool:
      vmImage: $(vmImageName)
    steps:
      - task: Docker@2
        displayName: Build and Push image
        inputs:
          repository: imgRepoName
          command: buildAndPush
          containerRegistry: "coreContainerRegistry"
          tags: test2

Issues:

When I wrote repository: "cqb-api" as the input for the docker task it works just fine, while use the variable directly as shown above won't create any images in the container registry.

PS, I also tried repository: $(imgRepoName) it give out the following error

invalid argument "***/$(basenamecore/cqb-api):test2" for "-t, --tag" flag: invalid reference format
0

1 Answer 1

2

It looks that it is executed at runtime. So gitreponame is replaced but basename function is not recognized in this context. You can check this:

variables:
  gitRepoName: $(Build.Repository.Name)

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
        $name = $(basename $(gitRepoName))
        Write-Host "##vso[task.setvariable variable=imgRepoName]$name"

- task: Docker@2
  displayName: Build and Push
  inputs:
    repository: $(imgRepoName)
    command: build
    Dockerfile: docker-multiple-apps/Dockerfile
    tags: |
      build-on-agent

It works for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.