1

enter image description here

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

David
  • 1,469
  • 5
  • 33
  • 51

2 Answers2

0

OK I have found an answer how to validate the branch name:

I can use a jenkins plugin : Validate String Parameter

See image attached enter image description here

Note the

This message is displayed to the user if they enter a value that does not match the configured regular expression.

I basically want the opposite ... I want the message to show WHEN the branch matches the regex:

^(www|api|admin)\w{1,26}$

Brain is frozen ... How do I do this?

David
  • 1,469
  • 5
  • 33
  • 51
0

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}$
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250