Azure Pipeline Task输入将不接受变量

时间:2020-05-07 10:11:53

标签: azure-devops yaml azure-pipelines azure-pipelines-tasks

在azure管道yaml文件中,从imgRepoName中修剪了变量gitRepoNamegitRepoName显示了core/cqb-api的bash回声; imgRepoName显示了cqb-api的bash回声

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

问题:

当我将repository: "cqb-api"用作docker任务的输入时,它可以正常工作,而直接使用上面显示的变量不会在容器注册表中创建任何图像。

PS,我也尝试过repository: $(imgRepoName),它发出了以下错误消息

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

1 个答案:

答案 0 :(得分:1)

它似乎在运行时执行。因此gitreponame被替换,但是在此上下文中无法识别基本名称功能。您可以检查以下内容:

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

对我有用。