【发布时间】:2019-10-27 18:33:12
【问题描述】:
总结
如何在 Azure Devops Pipeline YAML 文件中获取当前 git 标签的名称?
我想做什么?
我正在 Azure Devops 中设置构建管道。当创建新的 git 标签时,管道会触发。然后我想构建 docker 图像并用 git 标记的名称标记它们。
我的 YAML 管道如下所示:
# Trigger on new tags.
trigger:
tags:
include:
- '*'
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: 'ubuntu-latest'
steps:
- script: export VERSION_TAG={{ SOMEHOW GET THE VERSION TAG HERE?? }}
displayName: Set the git tag name as environment variable
- script: docker-compose -f k8s/docker-compose.yml build
displayName: 'Build docker containers'
- script: docker-compose -f k8s/docker-compose.yml push
displayName: 'Push docker containers'
我引用的 docker-compose 文件是这样的:
version: '3'
services:
service1:
image: my.privaterepo.example/app/service1:${VERSION_TAG}
build:
[ ... REDACTED ]
service2:
image: my.privaterepo.example/app/service2:${VERSION_TAG}
build:
[ ... REDACTED ]
如您所见,docker-compose 文件中的标签名称取自环境变量VERSION_TAG。在 YAML 管道中,我试图根据当前的 GIT 标签设置环境变量VERSION_TAG。那么...如何获取标签的名称?
【问题讨论】:
-
我尝试了以下操作:
export VERSION_TAG=`git describe --tags`。但是,这不起作用,因为....一些未知的原因。 -
不应该暴露一个构建变量吗??
-
@4c74356b41 应该是,但不是。请参阅下面的答案以获取解决方案。
标签: git azure-devops yaml azure-pipelines git-tag