问题描述
假设我想为同一脚本管道下的不同分支定义管道,如何为某些分支模式定义正则表达式.例如说:-
Suppose i want to define pipeline for different branches under same scripted pipeline, how to define the regex for certain pattern of branches. Say for example :-
if(env.BRANCH_NAME ==~ /release.*/){
stage("Deploy"){
echo 'Deployed release to QA'
}
在这里,我想以这种方式为模式的任何分支定义该正则表达式
Here i want to define that regex in such a way for any branch of the pattern
*release*
(表示其中包含释放字符串的任何分支).如何实现?
(meaning any branch with release string in it).How to achieve that?
类似地,如何实现类似:-
And similarly how to achieve something like :-
如果分支除了开发之外,请掌握,发布(模式).
if the branch is anything but develop, master, release(pattern).
推荐答案
如果您使用的是Groovy,则可以使用以下内容
If you're using groovy you may use the following
if ((env.BRANCH_NAME =~ '.*release.*').matches()) {
stage("Deploy"){
echo 'Deployed release to QA'
}
}
如果要匹配除develop
,master
或release
以外的任何分支名称,则可以使用以下正则表达式
And if you want to match any branch name but develop
, master
or release
, you may use the following regex
if ((env.BRANCH_NAME =~ '^((?!develop|master|release).)*$').matches()) {
stage("Deploy"){
echo 'Deployed release to QA'
}
}
这篇关于Jenkins脚本化管道中的分支指定符正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!