Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Overview

This article topic provides instructions on how to integrate Jenkins with the Unified Agent.

Unified Agent Configuration

The following integration uses environment variables to configure the Unified Agent so that the default configuration values are used.

For more information, see:

...

Pipeline Job on Windows Using CURL

...

Download CURL, add it to your PATH environment variable.

...

Authentication

For all the following examples, you will need to add the WhiteSource apiKey and a userKey to Jenkins Credential Manager, as a secret text.

For more information, see:

Pipeline Job on Linux/Unix and Windows Using CURL

In the 'Pipeline' select Definition: Pipeline script, and add the following lines to the script:

NOTE: It is advised to use the below curl commands only once a week to download the latest version of the Unified Agent for performance reasons and not as part of every build. You can do this using a scheduler task, such as corn.

...

Code Block
node {
  environment {
       WS_APIKEY = credentials('whitesource-apikey')
       WS_WSS_URL = "https://saas.whitesourcesoftware.com/agent"
       WS_USERKEY = credentials('whitesource-serviceaccount-userkey')
       WS_PRODUCTNAME = "Your Product Name"
       WS_PROJECTNAME = "${JOB_NAME}"
   }
  stage('Download 

...

Unified 

...

Agent') {
  

...

 sh 'curl -LJO https://

...

unified-agent.s3.amazonaws.com/

...

wss-unified-

...

agent.

...

jar'
  }
  stage('Run 

...

Unified 

...

Agent') {
    

...

sh '

...

java -

...

jar 

...

wss-

...

unified-agent.jar' 
  }
}

...

Note the following:

  • The first stage downloads the 'wss_agent.sh' script file to the job folder.

  • The second stage runs the script 'wss_agent.sh'. This script downloads For Windows, replace sh with bat and download CURL, add it to your PATH environment variable, and restart Jenkins to load the new PATH variable.

  • It is advised to use the download curl command only once a week to download the latest version of the WhiteSource Unified Agent JAR file and configuration file to your Jenkins job workspace. Afterwards, the script runs the JAR with the command line arguments of the Unified Agent.Make sure to edit the Unified Agent configuration file to match your specific requirementsUnified Agent for performance reasons, and not as part of every build. You can do this using a scheduler task, such as cron.

  • You can combine the two stages into one stage.

...

In the 'Pipeline', select Definition: Pipeline script and add the following lines to the script:

Code Block
node {
  stage('Download Unified Agent Jar') {environment {
       WS_APIKEY bat 'powershell bitsadmin /transfer mydownload /dynamic /download /priority FOREGROUND = credentials('whitesource-apikey')
       WS_WSS_URL = "https://githubsaas.whitesourcesoftware.com/whitesource/unified-agent-distribution/releases/latest/download/wss-unified-agent.jar $pwd\wss-unified-agent.jar'
  }

  agent"
       WS_USERKEY = credentials('whitesource-serviceaccount-userkey')
       WS_PRODUCTNAME = "your-product-name"
       WS_PROJECTNAME = "${JOB_NAME}"
   }
  stage('Download Unified Agent Configuration') {
    bat 'powershell bitsadmin /transfer mydownload /dynamic /download /priority FOREGROUND https://github.com/whitesource/unified-agent-distribution/raw/master/standAlone.s3.amazonaws.com/wss-unified-agent.configjar $pwd\wss-unified-agent.configjar'
  }
   stage('Run Unified Agent') {
    bat 'java -jar wss-unified-agent.jar -apiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx -c [path to config file] -project my-project -d [path to folder to scan]'
  }
}

Note the following:

...

  • The second stage downloads the latest version of the WhiteSource Unified Agent configuration file to the job folder.

  • The third stage runs the JAR with the command line arguments of the Unified Agent.

  • Make sure to edit the Unified Agent configuration file to match your requirements.

  • Make sure that Background Intelligent Transfer Service (BITS) is enabled on the node running the job.

  • You can combine the two stages into one stage.

Free Style Job on Linux/Unix and Windows Using CURL

  1. Download CURL, add it to your PATH environment variable.

  2. Restart Jenkins in order for it to load the new PATH variable.

  3. Go to Build Environment, click Use secret text(s) or file(s) and add your whitesource-apikey and whitesource-userkey credentials

  4. Go to Build, click on Add build step and then select Execute shell, Execute Windows batch command, or Run with timeout.

  5. Add the following commands on the new Command window:

    Code Block
    curl -LJO https://githubunified-agent.s3.amazonaws.com/whitesource/wss-unified-agent-distribution/raw/master/standAlone/wss_agent.shjar
    set wss_agent.sh -apiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx -c [path to config file] -project my-project -d [path to folder to scan]

...

Note the following: 

...

The first command downloads the 'wss_agent.sh' script file to the job folder.

...

The second command runs the script "wss_agent.sh". This script downloads the latest version of the WhiteSource Unified Agent JAR file and configuration file to your Jenkins job workspace.

...

Then the script runs the JAR with the command line arguments of Unified Agent.

...

  1. WS_PRODUCTNAME=your-product-name
    set WS_PROJECTNAME=${JOB_NAME}
    set WS_WSS_URL=https://saas.whitesourcesoftware.com/agent
    java -jar wss-unified-agent.jar

Free Style Job on Windows Using PowerShell

  1. Go to Build Environment, click Use secret text(s) or file(s) and add your whitesource-apikey and whitesource-userkey credentials.

  2. Go to Build, click on Add build step and then select Execute Windows batch command or Run with timeout.

  3. Add the following commands:

    Code Block
    powershell bitsadmin /transfer mydownload /dynamic /download /priority FOREGROUND https://github.com/whitesource/unified-agent-distribution/releases/latest/download.s3.amazonaws.com/wss-unified-agent.jar $pwd\wss-unified-agent.jar 
    powershell bitsadmin /transfer mydownload /dynamic /download /priority FOREGROUND set WS_PRODUCTNAME=your-product-name
    set WS_PROJECTNAME=${JOB_NAME}
    set WS_WSS_URL=https://githubsaas.whitesourcesoftware.com/whitesource/unified-agent-distribution/raw/master/standAlone/wss-unified-agent.config $pwd\wss-unified-agent.config 
    java -jar wss-unified-agent.jar -apiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx -c [path to config file] -project my-project -d [path to folder to
    scan]

Note the following:

...

The first command downloads the latest version of WhiteSource Unified Agent jar file to the job folder.

...

The second command downloads the latest version of the WhiteSource Unified Agent configuration file to the job folder.

...

The third command runs the JAR with the command line arguments of the Unified Agent.

...

  • Make sure that Background Intelligent Transfer Service (BITS) is enabled on the node that is running the job

...

Pipeline Job on Linux/Unix

In the 'Pipeline' select Definition: Pipeline script, and add the following lines to the script:

Code Block
node {
  stage('Download WS Script') {
    sh 'curl -LJO https://github.com/whitesource/unified-agent-distribution/raw/master/standAlone/wss_agent.sh'
  }

  stage('Run WS Script') {
    sh 'wss_agent.sh -apiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx -c [path to config file] -project my-project -d [path to folder to scan]' 
  }
}

...

Note the following

  • The first command downloads the 'wss_agent.sh' script file to the job folder.

  • The second command runs the script 'wss_agent.sh'. This script downloads the latest version of WhiteSource Unified Agent jar file and the configuration file to your Jenkins job workspace.

  • The script runs the JAR with the command line arguments of the Unified Agent.

  • Make sure to edit the Unified Agent configuration file to match your requirements.

  • Make sure that you have permission to download/execute the 'wss_agent.sh' script.

Free Style Job on Linux/Unix:

Go to Build, click on Add build step and then select Execute shell or Run with timeout.
Add the following commands in the new 'Command' window:

Code Block
curl -LJO https://github.com/whitesource/unified-agent-distribution/raw/master/standAlone/wss_agent.sh
wss_agent.sh -apiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx -c [path to config file] -project my-project -d [path to folder to scan]

...

Note the following:

  • The first command downloads the 'wss_agent.sh' script file to the job folder.

  • The second command runs the script 'wss_agent.sh'. This script downloads the latest version of WhiteSource Unified Agent jar file and the configuration file to your Jenkins job workspace.

  • The script runs the JAR with the command line arguments of the Unified Agent.

  • Make sure to edit the Unified Agent configuration file to match your requirements.

  • Make sure that you have the permission to download/execute the 'wss_agent.sh' script.