This topic describes how to use the Jenkins step in a Harness CD Pipeline.
Continuous Integration (CI) can be performed in Harness using the module and CI Pipelines.
If you are using Harness Continuous Delivery (CD) but not Harness Continuous Integration (CI), you can still perform CI using the Jenkins step in your CD Stage.
Harness integrates with Jenkins, enabling you to run Jenkins jobs and dynamically capture inputs and outputs from the jobs.
Supported Platforms and Technologies
Limitations and Requirements
- EnvInject Plugin: For Harness to capture Jenkins environment variables, your Jenkins configuration requires the EnvInject Plugin. The plugin does not provide full compatibility with the Pipeline Plugin. See Known limitations from Jenkins.
- CD and Custom stage types only: the Jenkins step is available in CD (Deploy) and Custom stages only.
Review: Jenkins Integration
With the Jenkins step, you can execute Jenkins jobs in the Stage's shell session.
When executing a job, you can also dynamically capture the output from the job, using runtime variables based on the context. You can then use those variables in another step in the same or other Stage or Pipeline.
What Information is Available to Capture?
Any Jenkins job information in the particular shell session of the Pipeline can be captured and output using one or more Jenkins steps. In addition, you can capture information available using the built-in Harness variables. For more information, see Built-in and Custom Harness Variables Reference.
Capturing and exporting output in the Jenkins step can be very powerful. For example, a Jenkins step could capture Jenkins build information, and a Harness Service could echo the build information and use it in a complex function, and then export the output down the Pipeline for further evaluation.
Step 1: Add the Jenkins Step
This step assumes you have a created a Pipeline and CD stage. If you are new to stages, see Add a Stage.
In your CD Stage's Execution, click Add Step, and then click Jenkins.
Step 2: Jenkins Connector
Select the Jenkins server you added as a Harness Jenkins Connector. For more information, see Connect to Jenkins.
Step 3: Job Name
Select the Jenkins job (also called a project) to execute. The list is automatically populated using the Jenkins Server you set up in the Jenkins Connector you selected.
Option: Use Runtime Inputs and Expressions
You can use Runtime Inputs or Expressions for the Jenkins Connector and Job Name.
Option: Job Parameters
If you are using a parameterized build, when you select the job in Job Name, Harness will automatically populate any Job parameters from the server.
You can also add parameters manually by clicking Add Job Parameter.
Runtime Inputs and Expressions are supported for the Value only.You can reference a Job parameter from the Input tab of the executed step.
|Job Parameters from Jenkins Step||Executed Jenkins step Inputs|
Option: Treat Unstable Jenkins Status as Success
If this setting is enabled then
Unstable statuses will be considered as
Option: Advanced Settings
In Advanced, you can use the following options:
Review: Captured Environment Variables from Jenkins Builds
For Harness to capture Jenkins environment variables, your Jenkins configuration requires the EnvInject Plugin. The plugin does not provide full compatibility with the Pipeline plugin. See Known Incompatibilities from Jenkins. Harness captures certain environment variables from the Jenkins build.
The following list shows examples of the environment variables and the expressions you can use to reference them:
- Job Status:
- Job URL:
- Build number:
- Build display name:
- Full build display name:
Here's a sample script
echo "Job Status:" <+execution.steps.Jenkins_Build.build.executionStatus>
echo "Job URL:" <+execution.steps.Jenkins_Build.build.jobUrl>
echo "Build number:" <+execution.steps.Jenkins_Build.build.buildNumber>
echo "Build display name:" <+execution.steps.Jenkins_Build.build.buildDisplayName>
echo "Full build display name:" <+execution.steps.[step_Id].build.buildFullDisplayName>
If you are using step groups the expressions must include the step group Ids also.
<+execution.steps.[step group Id].steps.[step Id].build.jobUrl>.
You can reference this Job information in subsequent steps in your pipeline or in another pipeline.
To reference the Job information in another stage in this pipeline, use the full pipeline path to the build information. For example,
Review: Multibranch Pipeline Support
For Harness to capture Jenkins environment variables, your Jenkins configuration requires the EnvInject Plugin. The plugin does not provide full compatibility with the Pipeline Plugin. See Known Incompatibilities from Jenkins.The Jenkins Multibranch Pipeline (Workflow Multibranch) feature enables you to automatically create a Jenkins pipeline for each branch on your source control repo.
Each branch has its own Jenkinsfile, which can be changed independently. This features enables you to handle branches better by automatically grouping builds from feature/experimental branches.
In Job Name, multibranch pipelines are displayed alongside other Jobs, with the child branches as subordinate options.
Click > and select the branch.
Review: Output Expressions
You can copy expressions for the Job outputs from the Output tab of the Jenkins step: