Configuring webhook triggers in Jenkins for a Multibranch pipeline job
Create a Multibranch pipeline job and set up the plug-in on it.
For more information, see Configuring the plug-in for a Multibranch pipeline job for the DevOps Code ClearCase-Jenkins integration.
Create a Jenkins API Token
For more information about how to obtain the user's API token, see https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/.
- Click the Sample Jenkinsfiles and scripts for Pipeline builds option to see the samples.
- Download a copy of the Perl script sample available in your Jenkins job settings.
- Edit the following variables in the Perl script where applicable:
- Postop Make Baseline Complete trigger script:
-
$HMACKEY. The secret key created in steps 7 and 8 of After completing Configuring webhook triggers in Jenkins.
-
$user. The Jenkins user.
-
$password. The Jenkins user API Token obtained from Create a Jenkins API Token.
-
$SERVER_URL. The URL where Jenkins is running.
-
$DEBUG. The default value is 0 to avoid print statements. You can change the value from 0 to 1 to see the print debug statements.
-
- Preop Deliver Start trigger script:
- $DEBUG. The default value is 0 to avoid print statements. You can change the value from 0 to 1 to see the print debug statements.
- MultiSite baseline polling script:
-
$TOKEN. The token created in step 2 from the Set the token for the Multibranch Scan Webhook Trigger plugin section.
-
$user. The Jenkins user.
-
$password. The Jenkins user API Token obtained from Create a Jenkins API Token.
-
$SERVER_URL. The URL where Jenkins is running.
-
$DEBUG. The default value is 0 to avoid print statements. You can change the value from 0 to 1 to see the print debug statements.
-
- Postop Make Baseline Complete trigger script:
- Install the trigger script in a file location where the ClearCase clients can access it (as you might do for any trigger script). Ensure that the Perl script has the correct permissions to be executed.
Optional (Applies only for the Postop Make Baseline Complete trigger): After completing Configuring webhook triggers in Jenkins
- Return to the Jenkins Dashboard.
- Go to the Manage Jenkins section and click Configure system.
- Search for the Generic Webhook Trigger section, and then select the Whitelist enabled check box, and click Add.
- Select the Verify with HMAC check box.Note: Do not enter a value in the IP, CIDR or IP range field.
- In the HMAC Header subsection, enter
X-VV-Signature
. At first, you must set up a new secret credential, otherwise proceed to step 9. - In the HMAC Secret subsection, click Add and select Jenkins.
- From the Kind drop-down, select the Secret text value.
- Enter a new Secret value and the ID for it, and then click Add.
- Select the new
credential ID created for HMAC Secret. Enter
HmacSHA256
in the HMAC Algorithm field. - Click Save to save your changes.
Postop Make Baseline Complete trigger script
The trigger is fired when the creation of a baseline is completed in a child stream of the integration stream configured in the Jenkins multibranch job for the desired VOB component. A new build of the affected stream will be started automatically in Jenkins.
Make sure you are in a view to create the postop mkbl_complete
trigger complete.
-
Create trigger scripts: Run the mktrtype command with the correct syntax arguments depending on the operating system for which the trigger will be created. For more information, see the following UNIX and Windows® examples.Note: Adjust the following flags as per your requirement. For more information about the mktrtype command, see mktrtype.
-
The -nc flag means no comments.
- The -print flag prints trigger execution output.
- The -postop mkbl_complete flag indicates that the trigger is fired when the creation of a baseline is completed.
-
The -execunix or -execwin flag is used to run a command or script in the right system at trigger firing.
UNIX example:cleartool mktrtype -nc -ucmobject -all -print -postop mkbl_complete -execunix "ratlperl full path to/perl script.pl" trigger_name@VOB_tag
Windows example:cleartool mktrtype -nc -ucmobject -all -print -postop mkbl_complete -execwin "ratlperl full path to\perl script.pl" trigger_name@VOB_tag
-
- Test the trigger by creating a new baseline and verifying the newly generated build of the stream in Jenkins.
Preop Deliver Start trigger script
The trigger is fired immediately on an attempt of a delivery operation, if the delivery is done from a stream, it creates a baseline and blocks the operation. If the delivery is done from a baseline , the trigger checks its Jenkins build attributes. When the baseline build attribute is COMPLETED_SUCCESFUL the delivery operation is allowed, otherwise it is blocked.
For more information about the Jenkins build attributes of a baseline, see the About the Enable build attributes on baseline section from Configuring the plug-in for a Multibranch pipeline job for the DevOps Code ClearCase-Jenkins integration.
Make sure you are in a view to create the preop deliver_start trigger.
- Create the trigger script. Run the mktrtype command with
the correct syntax arguments depending on the operating system for which the trigger
will be created. For more information, see the following UNIX and Windows® examples:Notes: Adjust the following flags as per your requirement. For more information about the mktrtype command, see mktrtype.
- The -nc flag means no comments.
- The -print flag prints trigger execution output.
- The -preop deliver_start flag indicates that the trigger is fired at the beginning of a delivery operation.
- The -execunix or -execwin flag is used to run a command or script in the right system at trigger firing.
- UNIX example:
cleartool mktrtype -nc -ucmobject -all -print -postop mkbl_complete -execunix "ratlperl full path to/perl script.pl" trigger_name@VOB_tag
- Windows example:
cleartool mktrtype -nc -ucmobject -all -print -postop mkbl_complete -execwin "ratlperl full path to\perl script.pl" trigger_name@VOB_tag
- Test the trigger by enabling the Baseline attributes on Jenkins and delivering a baseline.
MultiSite baseline polling script
The trigger is fired from a MultiSite environment when new baselines have been created in a replication packet and the packet is scanned before its import to the master VOB. After the packet import the Jenkins multibranch job will be called to scan for new baselines.
-
Install the Multibranch Scan Webhook Trigger plugin in Jenkins.
-
Select
. -
Search for the Multibranch Scan Webhook Trigger plugin and mark the Install check box.
-
Click on the Install button.
-
-
Set the token for the Multibranch Scan Webhook Trigger plugin.
-
Go to the Multibranch job settings.
-
Find the Scan Multibranch Pipeline Triggers section.
-
Select the Scan by webhook check box.
-
Enter the trigger token and click on the Save button.
-
-
Set up a RECEIPT_HANDLER for the MultiSite master replica to look at the sync_receive script. For UNIX, see shipping.conf.
For Windows see: MultiSite Control Panel.
For more information about the sync_receive script, see sync_receive.
-
For UNIX and Windows systems, open the sync_receive.bat script and insert the following code below the mentioned lines. Ensure to edit the location path of the
Jenkins MultiSite Baseline Polling
script according to the step 4 from the Create trigger scripts in DevOps Code ClearCase section before inserting the code:Line 690.
For UNIX:
# if new mkbaseline operations to be imported were found in the packet, # run the MultiSite Baseline Polling script to start a Baseline scan in the Jenkins instance. if ($exit_code_jenkins == 0) { dbgprint "***** Starting the MultiSite Baseline Polling script execution\n"; system("$interpreter /SCRIPT/LOCATION/PATH/jenkins_multisite_baseline_polling_script.pl"); dbgprint "\n***** Finished the MultiSite Baseline Polling script execution.\n"; }
For Windows:
# if new mkbaseline operations to be imported were found in the packet, # run the MultiSite Baseline Polling script to start a Baseline scan in the Jenkins instance. if ($exit_code_jenkins == 0) { dbgprint "***** Starting the MultiSite Baseline Polling script execution\n"; system("$interpreter <Drive Letter>:\\SCRIPT\\LOCATION\\PATH\\jenkins_multisite_baseline_polling_script.pl"); dbgprint "\n***** Finished the MultiSite Baseline Polling script execution.\n"; }
Example of how the code must look like:
Line 625.
For UNIX:
my $interpreter = $Config{perlpath}; $exit_code_jenkins = 1; # if the packet file exists, run the MultiSite Baseline Polling script to scan the packet looking for new mkbaseline operations. # the script will return 0 if new mkbaseline operations to be imported were found. if (-e $pkt) { dbgprint "***** Starting the MultiSite Baseline Polling script execution\n"; $exit_code_jenkins = system("$interpreter /SCRIPT/LOCATION/PATH/jenkins_multisite_baseline_polling_script.pl -pkt $pkt"); dbgprint "***** MultiSite Baseline Polling script exit code: $exit_code_jenkins\n"; }
For Windows:
my $interpreter = $Config{perlpath}; $exit_code_jenkins = 1; # if the packet file exists, run the MultiSite Baseline Polling script to scan the packet looking for new mkbaseline operations. # the script will return 0 if new mkbaseline operations to be imported were found. if (-e $pkt) { dbgprint "***** Starting the MultiSite Baseline Polling script execution\n"; $exit_code_jenkins = system("$interpreter <Drive Letter>:\\SCRIPT\\LOCATION\\PATH\\jenkins_multisite_baseline_polling_script. pl -pkt \"$pkt\""); dbgprint "***** MultiSite Baseline Polling script exit code: $exit_code_jenkins\n"; };
Example of how the code must look like:
Line 465
my $exit_code_jenkins;
Example of how the code must look like:
-
Test the script by importing a replication packet which contains new baselines and verifying the newly generated baseline scan in Jenkins.Note: The debug output of the
sync_receive.bat
script can be enabled by uncommenting the code line number 74. To uncomment the code, delete the # symbol at the beginning of the line. The shipping_receive_log file is stored in the /var/adm/rational/ccase/log directory on Linux and the UNIX system and the \var\log directory on Windows.Example of how the code must look like: