4.0 KiB
Perform a dry-run of a Jenkins pipeline
In this lab you will use the dry-run command to convert a Jenkins pipeline to its equivalent GitHub Actions workflow.
Prerequisites
- Followed the steps here to set up your Codespace environment and start a Jenkins server.
- Completed the configure lab.
- Completed the audit lab.
Perform a dry-run
We will be performing a dry-run against a pipeline in your preconfigured Jenkins server. We will need to answer the following questions before running this command:
-
What is the name of the pipeline we want to convert?
- test_pipeline
-
What is the URL of the pipeline we want to convert?
-
Where do we want to store the result?
- ./tmp/dry-run-lab. This can be any path within the working directory that Valet commands are executed from.
Steps
-
Navigate to the codespace terminal
-
Run the following command from the root directory:
gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run -
The command will list all the files written to disk when the command succeeds.
-
View the converted workflow:
- Find
./tmp/dry-runin the file explorer pane in codespaces. - Click
test_pipeline.ymlto open
- Find
Inspect the output files
The files generated from the dry-run command represent the equivalent Actions workflow for the given Jenkins pipeline. The Jenkins pipeline and converted workflow can be seen below:
Jenkins pipeline 👇
pipeline {
agent {
label 'TeamARunner'
}
environment {
DISABLE_AUTH = 'true'
DB_ENGINE = 'sqlite'
}
stages {
stage('build') {
steps {
echo "Database engine is ${DB_ENGINE}"
sleep 80
echo "DISABLE_AUTH is ${DISABLE_AUTH}"
}
}
stage('test') {
steps{
junit '**/target/*.xml'
}
}
}
}
Converted workflow 👇
name: test_pipeline
on:
push:
paths: "*"
schedule:
- cron: 0-29/10 * * * *
env:
DISABLE_AUTH: 'true'
DB_ENGINE: sqlite
jobs:
build:
runs-on:
- self-hosted
- TeamARunner
steps:
- name: checkout
uses: actions/checkout@v2
- name: echo message
run: echo "Database engine is ${{ env.DB_ENGINE }}"
# # This item has no matching transformer
# - sleep:
# - key: time
# value:
# isLiteral: true
# value: 80
- name: echo message
run: echo "DISABLE_AUTH is ${{ env.DISABLE_AUTH }}"
test:
runs-on:
- self-hosted
- TeamARunner
needs: build
steps:
- name: checkout
uses: actions/checkout@v2
- name: Publish test results
uses: EnricoMi/[email protected]
if: always()
with:
files: "**/target/*.xml"
These 2 pipelines function equivantly despite using different syntax. In this case, the pipeline conversion was “partially successful” (i.e. there were item(s) not automatically converted) and the unconverted item was placed as comment in the location the Jenkins pipeline used it. For example:
- sleep 80
+ # # This item has no matching transformer
+ # - sleep:
+ # - key: time
+ # value:
+ # isLiteral: true
+ # value: 80
In the next lab, we'll learn how to override Valet's default behavior and customize the converted workflow that is generate.
Try running the dry-run command for different pipelines in the Jenkins server. As a hint, you just have to change the --source-url CLI option.
