Azure devops 如何在azure-pipelines.yml文件中为docker映像添加自定义生成标记?
我们正在为我们的项目使用Azure DevOps。我有一个Azure devops 如何在azure-pipelines.yml文件中为docker映像添加自定义生成标记?,azure-devops,azure-devops-rest-api,Azure Devops,Azure Devops Rest Api,我们正在为我们的项目使用Azure DevOps。我有一个azurepipelines.yml文件,它使用docker图像标记的构建id。但是,我们希望手动添加docker映像id作为构建定义的一部分 是否可以将运行时参数从构建队列rest api传递到azure-pipelines.yml文件 azure-pipelines.yml 生成队列的请求主体 是否可以从生成队列rest api传递运行时参数 到azure-pipelines.yml文件 不确定运行时参数的确切含义。但我想您需要的是使
azurepipelines.yml
文件,它使用docker图像标记的构建id。但是,我们希望手动添加docker映像id作为构建定义的一部分
是否可以将运行时参数从构建队列rest api传递到azure-pipelines.yml文件
azure-pipelines.yml
生成队列的请求主体
是否可以从生成队列rest api传递运行时参数
到azure-pipelines.yml文件
不确定运行时参数的确切含义。但我想您需要的是使用RESTAPI构建队列,同时将动态变量传递给管道
示例场景:
{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/master"
}
}
},
"templateParameters": {
"tag": "new"
}
}
这是我的azure管道。yml:
parameters:
- name: tag
type: string
default: 'aaa'
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
displayName: build
inputs:
containerRegistry: DockerHub
repository: {my docker repos}
command: build
Dockerfile: Docker/TestWebApi/Dockerfile
tags: '${{ parameters.tag }}'
- task: Docker@2
displayName: push
inputs:
containerRegistry: DockerHub
repository: {my docker repos}
command: push
tags: '${{ parameters.tag }}'
您可以看到,它需要的动态图像标记是parametertag
。当我使用rest api将此管道排队时,它将被传递一个新值:
https://dev.azure.com/{org}/{project}/_apis/pipelines/{definition id}/runs?api-version=5.1-preview.1
正文:
{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/master"
}
}
},
"templateParameters": {
"tag": "new"
}
}
只需在请求体中配置要传递到的变量
增加:
"variables": {
"myVariable": {
"value": "0325ApiQueue"
}
是否可以从生成队列rest api传递运行时参数
到azure-pipelines.yml文件
不确定运行时参数的确切含义。但我想您需要的是使用RESTAPI构建队列,同时将动态变量传递给管道
示例场景:
{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/master"
}
}
},
"templateParameters": {
"tag": "new"
}
}
这是我的azure管道。yml:
parameters:
- name: tag
type: string
default: 'aaa'
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
displayName: build
inputs:
containerRegistry: DockerHub
repository: {my docker repos}
command: build
Dockerfile: Docker/TestWebApi/Dockerfile
tags: '${{ parameters.tag }}'
- task: Docker@2
displayName: push
inputs:
containerRegistry: DockerHub
repository: {my docker repos}
command: push
tags: '${{ parameters.tag }}'
您可以看到,它需要的动态图像标记是parametertag
。当我使用rest api将此管道排队时,它将被传递一个新值:
https://dev.azure.com/{org}/{project}/_apis/pipelines/{definition id}/runs?api-version=5.1-preview.1
正文:
{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/master"
}
}
},
"templateParameters": {
"tag": "new"
}
}
只需在请求体中配置要传递到的变量
增加:
"variables": {
"myVariable": {
"value": "0325ApiQueue"
}
手动添加构建id是什么意思?您可以创建一个变量,并使用$(您的标记)将其传递给标记。当我在标记中传递env变量时,我会收到此错误##[错误]对于“-t,-tag”标志的参数“***.azurecr.io/project:$(dockertagvar)”无效:引用格式无效。为什么它不读取变量的内容?@cell in您可以试试这个
${{parameters.tag}}
并参考答案。手动添加构建id是什么意思?您可以创建一个变量并使用$(您的标记)将其传递给标记。当我在标记中传递env变量时,我得到了这个错误##[错误]对于“-t,-tag”标志的参数“***.azurecr.io/project:$(dockertagvar)”无效:引用格式无效。为什么它不读取变量的内容?@cell in您可以试试这个${{parameters.tag}
并参考答案。我正在使用生成队列api来运行生成定义。如何在参数属性中添加值?@kumareshbabons,您的意思是您在YAML管道中定义了参数属性吗?是的。我正在使用运行生成定义。有一个选项“参数”。我们可以用它传递标签号吗?@kumareshbabons,当然可以。请参阅我的更新答案。@kumareshbabons。是的,前面的api是为UI配置的管道工作的。对于YAML管道,您需要使用第二个管道,这是我在回答中共享的管道。很高兴知道你现在成功了!我正在使用构建队列api来运行构建定义。如何在参数属性中添加值?@kumareshbabons,您的意思是您在YAML管道中定义了参数属性吗?是的。我正在使用运行生成定义。有一个选项“参数”。我们可以用它传递标签号吗?@kumareshbabons,当然可以。请参阅我的更新答案。@kumareshbabons。是的,前面的api是为UI配置的管道工作的。对于YAML管道,您需要使用第二个管道,这是我在回答中共享的管道。很高兴知道你现在成功了!