在azure管道yaml文件中,从imgRepoName
中修剪了变量gitRepoName
。 gitRepoName
显示了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
答案 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
对我有用。