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/.

Create trigger scripts in DevOps Code ClearCase®
  1. Click the Sample Jenkinsfiles and scripts for Pipeline builds option to see the samples.
  2. Download a copy of the Perl script sample available in your Jenkins job settings.
  3. Edit the following variables in the Perl script where applicable:
    1. Postop Make Baseline Complete trigger script:
      1. $HMACKEY. The secret key created in steps 7 and 8 of After completing Configuring webhook triggers in Jenkins.

      2. $user. The Jenkins user.

      3. $password. The Jenkins user API Token obtained from Create a Jenkins API Token.

      4. $SERVER_URL. The URL where Jenkins is running.

      5. $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.

    2. Preop Deliver Start trigger script:
      1. $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.
    3. MultiSite baseline polling script:
      1. $TOKEN. The token created in step 2 from the Set the token for the Multibranch Scan Webhook Trigger plugin section.

      2. $user. The Jenkins user.

      3. $password. The Jenkins user API Token obtained from Create a Jenkins API Token.

      4. $SERVER_URL. The URL where Jenkins is running.

      5. $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.

  4. 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

  1. Return to the Jenkins Dashboard.
  2. Go to the Manage Jenkins section and click Configure system.
  3. Search for the Generic Webhook Trigger section, and then select the Whitelist enabled check box, and click Add.
  4. Select the Verify with HMAC check box.
    Note: Do not enter a value in the IP, CIDR or IP range field.
  5. In the HMAC Header subsection, enter X-VV-Signature. At first, you must set up a new secret credential, otherwise proceed to step 9.
  6. In the HMAC Secret subsection, click Add and select Jenkins.
  7. From the Kind drop-down, select the Secret text value.
  8. Enter a new Secret value and the ID for it, and then click Add.
  9. Select the new credential ID created for HMAC Secret. Enter HmacSHA256 in the HMAC Algorithm field.
  10. Click Save to save your changes.
Note: Using a secret credential to sign the payload is a good way to protect Jenkins from rogue request senders.

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.

Note: You need to create the trigger script logged as the VOB owner.
  1. 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.
    1. The -nc flag means no comments.

    2. The -print flag prints trigger execution output.
    3. The -postop mkbl_complete flag indicates that the trigger is fired when the creation of a baseline is completed.
    4. 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
  2. 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.

Note: You need to create the trigger script logged as the VOB owner.
  1. 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
  2. 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.

  1. Install the Multibranch Scan Webhook Trigger plugin in Jenkins.

    1. Select Manage Jenkins > Manage Plugins > Available Plugins.

    2. Search for the Multibranch Scan Webhook Trigger plugin and mark the Install check box.

    3. Click on the Install button.

  2. Set the token for the Multibranch Scan Webhook Trigger plugin.

    1. Go to the Multibranch job settings.

    2. Find the Scan Multibranch Pipeline Triggers section.

    3. Select the Scan by webhook check box.

    4. Enter the trigger token and click on the Save button.

  3. 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.

  4. 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:


    DevOps Code ClearCase

    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:


    DevOps Code ClearCase

    Line 465

    my $exit_code_jenkins;

    Example of how the code must look like:


    DevOps Code ClearCase
  5. 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:


    DevOps Code ClearCase