[英]How to use regular expression in a JenkinsFile multibranch pipeline?
I've a multibranch pipeline jenkins file.我有一个多分支管道 jenkins 文件。 I would like to be able to use a custom workspace, which includes this:我希望能够使用自定义工作区,其中包括:
pipeline {
agent {
node{
label 'windows-node'
customWorkspace "${env.BRANCH_NAME}"
}
}
//...
}
I would like to be able to extract one part of my branch name to do the regular expression.我希望能够提取我的分支名称的一部分来做正则表达式。
my branches have the following structures:我的分支机构具有以下结构:
And I would like my workspace to be only BR-X if present, so in my case:我希望我的工作区只有 BR-X(如果存在),所以在我的情况下:
I'm totally capable to do one regular expression to extract this from this text, but I don't see how to extract this regex and use it as customWorkspace.我完全有能力做一个正则表达式来从文本中提取它,但我不知道如何提取这个正则表达式并将其用作 customWorkspace。
Any idea?任何的想法?
If understand correctly, I use the condition checks in pipeline like this, I abort my pipeline if branch is not of this pattern.如果理解正确,我会像这样在管道中使用条件检查,如果分支不是这种模式,我会中止管道。
when {
not {
anyOf {
branch 'feat/*';
branch 'feature/*'
branch 'bug/*'
branch 'bugfix/*'
branch 'release/*'
branch 'hotfix/*'
branch 'PR-*'
branch 'e2e/*'
branch 'develop'
branch 'fix/*'
}
}
}
or you can also use或者你也可以使用
when { branch pattern: "release-\\d+", comparator: "REGEXP"}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.