Jenkinsfile获取当前标签 [英] Jenkinsfile get current tag

查看:117
本文介绍了Jenkinsfile获取当前标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以获取Jenkinsfile中作业的当前标签(如果没有,则为null)?背景是,当此提交具有标签时,我只想构建一些工件(android APKs). 我试过了:

Is there a way to get the current tag ( or null if there is none ) for a job in a Jenkinsfile? The background is that I only want to build some artifacts ( android APKs ) when this commit has a tag. I tried:

env.TAG_NAME

binding.variables.get("TAG_NAME")

始终都是空的-即使这个( https://issues.jenkins-ci .org/browse/JENKINS-34520 )表示相反

both are always null - even though this ( https://issues.jenkins-ci.org/browse/JENKINS-34520 ) indicates otherwise

推荐答案

我会考虑使用returnStdout而不是写入文件:

I'd consider returnStdout rather than writing to a file:

sh(returnStdout: true, script: "git tag --sort version:refname | tail -1").trim()

这篇关于Jenkinsfile获取当前标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆