Nested and parallel stages in Jenkins pipelines
Summarize
Summary of Nested and parallel stages in Jenkins pipelines
ServiceNow DevOps supports the use of nested and parallel stages in scripted Jenkins pipelines to accelerate pipeline execution by running tasks concurrently. This feature enables better automation for complex workflows such as running multiple test cases across different operating systems and browsers simultaneously. The ServiceNow DevOps pipeline UI reflects these nested and parallel stages in real time, mirroring the Jenkins pipeline UI and providing detailed views including build artifacts, test results, software quality summaries, and change request details.
Show less
Important: Support for nested and parallel stages applies only to scripted Jenkins pipelines. Freestyle pipelines display stages sequentially in the DevOps pipeline UI, regardless of parallel or nested configurations in Jenkins.
Key Features
- Real-time rendering of Jenkins pipelines with nested and parallel stages in the ServiceNow DevOps pipeline UI.
- Creation of change requests for each nested and parallel stage after all upstream events are received, improving granularity and control over pipeline approvals.
- Pipeline execution pauses if a change request approval is required, resuming automatically once approved.
- Support for complex pipeline structures, including multiple levels of parallel stages nested within other stages, enabling flexible and efficient orchestration.
Change Requests in Nested and Parallel Stages
Change requests are now generated for every nested and parallel stage rather than only for parent stages as in previous releases. This allows for more precise change management and approval workflows aligned with the actual pipeline execution steps. Customers must ensure that appropriate approval groups are assigned to each nested or parallel stage to avoid execution delays.
Upgrade Considerations
- Perform upgrades during off-peak hours to avoid disruptions.
- Ensure no pipeline executions are in progress in ServiceNow DevOps during the upgrade to prevent missing step executions.
- If pipeline runs were active during the upgrade, rerun them to properly create step executions for nested and parallel stages.
Use nested and parallel stages in scripted Jenkins pipelines to speed up your pipeline execution. Change requests are created for nested and parallel stages and not just for the parent stage.
Support for nested and parallel stages in Jenkins pipelines
You can use nested and parallel stages in scripted Jenkins pipelines to automate and speed up tasks that can be run in parallel. For example, you have a scripted Jenkins pipeline with nested and parallel stages for various test cases such as different quality checks for different operating systems and browsers.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
// Your build steps here
}
}
stage('Test') {
parallel {
stage('Unit Tests') {
steps {
echo 'Running unit tests...'
// Your unit test steps here
}
}
stage('Integration Tests') {
steps {
echo 'Running integration tests...'
// Your integration test steps here
}
}
stage('Additional Tests') {
steps {
script {
parallel(
'Nested Stage 1': {
echo 'Running nested parallel stage 1...'
// Your nested parallel stage 1 steps here
},
'Nested Stage 2': {
echo 'Running nested parallel stage 2...'
// Your nested parallel stage 2 steps here
}
)
}
}
}
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
snDevOpsChange changeRequestDetails: '{ "attributes": {"chg_model": "e55d0bfec343101035ae3f52c1d3ae49","standard_change_template"="563504cc47410200e90d87e8dee490e2"},"autoCloseChange": false}',changeStepTimeOut: 18000, pollingInterval: 60
// Your deploy steps here
}
}
}
}
Change requests in nested and parallel stages
Change requests are created for all nested and parallel stages, once all upstream events (prior to the change request) are received. In previous releases, nested or parallel stages in Jenkins pipelines were not identified nor processed in ServiceNow DevOps. Only parent stages were identified and processed in a linear or sequential manner. If change requests existed as part of any nested and parallel stages, those change requests were ignored and a single change request was processed as part of the parent stage. When you run a new pipeline after upgrading, new steps and steps executions are created for nested stages.
Nested and parallel stages were not processed previously, and approval groups were mapped only to the parent stage. Because nested and parallel stages are identified during processing, you must verify that relevant approval groups are mapped to the appropriate nested or parallel stage. If subsequent steps of the pipeline are dependent on the change request's being approved, the pipeline execution is paused, and resumed when the change request is approved.
Upgrade Considerations
- Upgrade during off-peak hours.
- Ensure that you do not have any pipeline executions that are currently in progress by ServiceNow DevOps. If pipeline executions are being processed, step executions might not be created as expected for the in-progress pipeline runs. Rerun the pipeline to create appropriate step executions.