如何在jenkins参数化作业中验证github分支名称作为字符串参数? [英] How can I validate a github branch name as a string parameter in jenkins parametrized job?

查看:239
本文介绍了如何在jenkins参数化作业中验证github分支名称作为字符串参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我如何在jenkins中做一些github分支名称验证?



分支应该只包含26个字母数字字符和连字符
分支应该 NOT www api admin 一个正则表达式可能是:

$ p $ ^(?! www)(?! admin)(?! api)[ a-zA-Z0-9。] {1,26} $

我的问题是我想在作业运行时执行此验证。



我应该在jenkins中将分支名称的这种正则表达式验证放在哪里?

PS:在附图中,该分支是非法的分支名称......它打破了验证规则,因为它以www开头。 b
$ b

感谢您

解决方案

您可以看到不以序列开头的字符串的正则表达式,并查看Jenkins中使用的正则表达式引擎(我想是否为java)允许负面查找,提前断言:

$ $ p $ ^(?!www |?!api |?!admin)\w {1,26} $
#或
^(!!(www | api | admin))\w {1,26} $


How can I do some github branch name validation in jenkins?

branch should contain only 26 alphanumeric characters and hyphens branch should NOT begin with www, api or admin

One regex for this could be:

^(?!www)(?!admin)(?!api)[a-zA-Z0-9.]{1,26}$

My problem is that I want to do this validation when the job is run.

Where should i put such regex validation for the branch name in jenkins?

PS: in the attached image, that branch for instance is an illegal branch name ... it breaks the validation rule because it starts with www.

thank you

解决方案

You can see "Regular expression for a string that does not start with a sequence" and see if the regexp engine used within Jenkins (the java one I suppose) allows for a negative look-ahead assertion:

^(?!www|?!api|?!admin)\w{1,26}$
# or
^(?!(www|api|admin))\w{1,26}$

这篇关于如何在jenkins参数化作业中验证github分支名称作为字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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