在詹金斯工作中使用git repo name作为ENV变量 [英] use git repo name as ENV variable in jenkins job
问题描述
我正在尝试找出一种方法来获取jenkins作业中的远程git项目名称作为env变量.当詹金斯克隆存储库时,我想将项目名称用作本地子目录名称".有办法吗?
I am trying to figure out a way to get the remote git project name in a jenkins job as a env variable. I would like to use the project name as the "local subdirectory name" when jenkins clones the repo. is there a way to do this?
可能类似于${GIT_REPO_NAME}
我知道这里有${GIT_REPO_URL}
,它包括项目名称,但是我需要能够在本地子目录字段中使用它.
I know that there is ${GIT_REPO_URL}
and it includes the project name, but I need to be able to use this in the local sub directory field.
如果有人对此有更好的解决方案,我会为之
if someone has a better solution for this I am all ears.
谢谢!
推荐答案
这是一个简单的单行代码:
Here's a simple one-liner:
env.GIT_REPO_NAME = env.GIT_URL.replaceFirst(/^.*\/([^\/]+?).git$/, '$1')
/^.*\/([^\/]+?).git$/
是一个正则表达式,仅创建回购名称的后向引用.
/^.*\/([^\/]+?).git$/
is a regex that creates a back-reference to just the repo name.
这篇关于在詹金斯工作中使用git repo name作为ENV变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!