jenkins-library icon indicating copy to clipboard operation
jenkins-library copied to clipboard

Create option commitsAllowed for GenericPipeline - for LF jenkins

Open jackjia-ibm opened this issue 4 years ago • 0 comments

Problem to solve

To mitigate the permission issue on LF Jenkins, we need a new way to trigger build on Jenkins manually.

Solution

Introduce commitsAllowed as String[] and with value of RegExp strings. This property will defines what commit messages could trigger a build.

  • If the value is empty List or null, the build will be triggered by default settings for every commit,
  • If the value is not empty, the build will check the changes list and see if the last commit matches the pre-defined pattern.
  • If commit can also have customized information for build parameters, and one line for each parameter.
  • Pipeline should read through the commit message line by line, skip the first line which we used to match the commitsAllowed and then see if other lines match pattern of key=value. key should be string like [a-zA-Z0-9 \-_] which are characters we usually used to define build parameters, value could be any value to the end of the line.
  • If the user want to start another test, they must push another commit,
  • This check can be a new stage automatically added in GenericPipeline setupGeneric method, it has to happen after the code base is checked out.

Example

For zowe-install-test pipeline, define the pipeline commitsAllowed to be ['\[zowe-install-test\]']. There is no zowe-install-test build be triggered by default due to this setting. To start a manual test, run this command:

git commit -s --allow-empty -m "[zowe-install-test]" -m "TEST_SERVER=marist-2" -m "ZOWE_ARTIFACTORY_PATTERN =https://zowe.jfrog.io/......" -m "ZOWE_ARTIFACTORY_BUILD="
git push

When pipeline is kicked off by this commit, the pipeline matches pattern [zowe-install-test] and will resolve the build parameters, in this example, TEST_SERVER, ZOWE_ARTIFACTORY_PATTERN , and ZOWE_ARTIFACTORY_BUILD value, and then start the build.

Potential Issues

params.[build-parameter] is available all the time, but with this approach, the value of params.[build-parameter] is not trustworthy because it could be changed by the setup step.

jackjia-ibm avatar Nov 27 '20 15:11 jackjia-ibm