Jenkins / Git: create the last of the branches + manual assembly from any commit

I am trying to configure Jenkins using a Git project to:

  • It will build from branches matching the pattern (origin / master, origin / feature / *, origin / hotfix / *, etc.) when the changes are transferred to the central repository

  • Developers and testers can initiate assembly for any required edition, specified as an assembly parameter, which is a tag name, branch name, or commit hash. The task has other parameters, and sometimes we want to create assemblies with something other than the default values.

I have 1. working correctly by setting up a post-receive script on a Git server and adding a few branch qualifiers to Jenkins.

To do 2., I added an additional build parameter to GitRef , and then added an additional branch specifier with $GitRef . Manually, starting the assembly, it will simply continue to build from the same commit / branch each time, regardless of which parameter was set. If I deleted all the other branch specifiers, the manual assembly would work as expected. But then the assemblies built with the help of the hook will build only from origin / master (the default value is $GitRef ).

Am I trying to achieve even without creating two jobs for each project? If so, what do I need to do to make it work?

+6
source share
2 answers

If you install the Git Parameter Plugin , you can allow users to run a parameterized assembly using a specific commit identifier, branch, or tag.

You can then set the default value for your parameters as ** , and by default, Jenkins will build the last commit in the branches.

+2
source

Instead of using $GitRef as another branch qualifier, just use it as a String variable with no default value. Then, as the first step of your build phase in Jenkins, enter a script that checks if this value is set:

 #!/bin/bash if [ -n $GitRef ] then echo "Manually specified reference found. Building $GitRef" git checkout $GitRef else echo "No explicit branch specified, building $GIT_BRANCH" fi 

At this point, run your build as usual (e.g. Maven). Any branch / tag / commit command that you want to compile will be executed in the assembly, and if it does not exist, Jenkins must take care of git checkout <bad_ref> without having to complete the assembly.

+1
source

Source: https://habr.com/ru/post/954959/


All Articles