如何在 azure-pipelines.yml 文件中为 docker 图像添加自定义构建标签?
How to add custom build tags for docker images in azure-pipelines.yml file?
我们正在为我们的项目使用 Azure DevOps。我有 azure-pipelines.yml
文件,它使用 docker 图像标签的构建 ID。但是,我们希望手动添加 docker 图像 ID 作为构建定义的一部分。
是否可以将运行时参数从构建队列剩余 api 传递到 azure-pipelines.yml 文件?
azure-pipelines.yml
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
resources:
- repo: self
variables:
imageName: 'sampleapp1'
dockerhubNS: 'kumaresh'
steps:
- task: Docker@2
displayName: Login to Docker Hub
inputs:
command: login
containerRegistry: dh-connection
- task: Docker@2
displayName: Build and Push an image
inputs:
command: buildAndPush
dockerfile: Dockerfile
containerRegistry: dh-connection
repository: $(dockerhubNS)/$(imageName)
tag: $(appBuildNumber)
Request Body for Build Queue
"definition": {
"id": Build_Definition_Id,
"name": extractDefinitionName,
"type": "build"
},
"templateParameters": {
"tag": "1"
}
Is it possible to pass the runtime arguments from build queue rest api
to azure-pipelines.yml file?
不确定运行时参数的确切含义。但我想你正在寻找的是用 rest api 构建队列,同时将动态变量传递给管道。
示例场景:
这是我的 azure-pipeline.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 }}'
可以看到,它需要的动态图片标签是参数tag
。当我用 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"
}
我们正在为我们的项目使用 Azure DevOps。我有 azure-pipelines.yml
文件,它使用 docker 图像标签的构建 ID。但是,我们希望手动添加 docker 图像 ID 作为构建定义的一部分。
是否可以将运行时参数从构建队列剩余 api 传递到 azure-pipelines.yml 文件?
azure-pipelines.yml
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
resources:
- repo: self
variables:
imageName: 'sampleapp1'
dockerhubNS: 'kumaresh'
steps:
- task: Docker@2
displayName: Login to Docker Hub
inputs:
command: login
containerRegistry: dh-connection
- task: Docker@2
displayName: Build and Push an image
inputs:
command: buildAndPush
dockerfile: Dockerfile
containerRegistry: dh-connection
repository: $(dockerhubNS)/$(imageName)
tag: $(appBuildNumber)
Request Body for Build Queue
"definition": {
"id": Build_Definition_Id,
"name": extractDefinitionName,
"type": "build"
},
"templateParameters": {
"tag": "1"
}
Is it possible to pass the runtime arguments from build queue rest api to azure-pipelines.yml file?
不确定运行时参数的确切含义。但我想你正在寻找的是用 rest api 构建队列,同时将动态变量传递给管道。
示例场景:
这是我的 azure-pipeline.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 }}'
可以看到,它需要的动态图片标签是参数tag
。当我用 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"
}