Azure 管道任务输入不接受变量
Azure Pipeline Task inputs won't accept variables
在 azure pipeline yaml 文件中,变量 imgRepoName
是从 gitRepoName
中删除的。 core/cqb-api
gitRepoName
的 bash 回显; bash 显示 imgRepoName
的回显 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
问题:
当我写 repository: "cqb-api"
作为 docker 任务的输入时它工作得很好,而直接使用变量如上所示不会在容器注册表中创建任何图像。
PS, 我也试过repository: $(imgRepoName)
报错如下
invalid argument "***/$(basenamecore/cqb-api):test2" for "-t, --tag" flag: invalid reference format
看起来是在运行时执行的。因此 gitreponame
被替换,但在此上下文中无法识别 basename 函数。你可以检查这个:
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
对我有用。
在 azure pipeline yaml 文件中,变量 imgRepoName
是从 gitRepoName
中删除的。 core/cqb-api
gitRepoName
的 bash 回显; bash 显示 imgRepoName
的回显 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
问题:
当我写 repository: "cqb-api"
作为 docker 任务的输入时它工作得很好,而直接使用变量如上所示不会在容器注册表中创建任何图像。
PS, 我也试过repository: $(imgRepoName)
报错如下
invalid argument "***/$(basenamecore/cqb-api):test2" for "-t, --tag" flag: invalid reference format
看起来是在运行时执行的。因此 gitreponame
被替换,但在此上下文中无法识别 basename 函数。你可以检查这个:
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
对我有用。