33
Setup a Jenkins CI/CD pipeline for your AltWalker tests
This tutorial should help you setup a CI/CD pipeline on Jenkins for your AltWalker tests.
Copy one of the examples below into your repository and name it Jenkinsfile
. Try modifying the sh
command to run the same command you would run on your local machine.
pipeline {
agent {
docker {
image 'altwalker/altwalker:latest'
args '-u root:root'
}
}
stages {
stage('test') {
steps {
sh 'altwalker online tests -m model/default.json "random(vertex_coverage(100))"'
}
}
}
}
Click the New Item menu within Jenkins
Provide a name for your new item (e.g. My-AltWalker-Pipeline) and select Multibranch Pipeline.
Click the Add Source button, choose the type of repository you want to use and fill in the details.
Click the Save button and watch your first Pipeline run!
Below are some easily copied and pasted examples of a simple Pipeline for Python and .NET.
pipeline {
agent {
docker {
image 'altwalker/altwalker:latest'
args '-u root:root'
}
}
stages {
stage('test') {
steps {
sh 'altwalker online tests -m models/model.json "random(vertex_coverage(100))"'
}
}
}
}
pipeline {
agent {
docker {
image 'altwalker/altwalker:latest-dotnet-3.1'
args '-u root:root'
}
}
stages {
stage('test') {
steps {
sh 'altwalker online tests --language dotnet -m models/model.json "random(vertex_coverage(100))"'
}
}
}
}
For more information about all the tags supported by the AltWalker docker images check out the docker repository for
altwalker/altwalker
. After you setup for first pipeline:
To generate the XML reports add the --report-xml
to your online
or walk
command.
Inside the Jenkinsfile
after the online
or walk
command add the following line:
junit 'report.xml'
For a python project the
Jenkinsfile
should look like this:pipeline {
agent {
docker {
image 'altwalker/altwalker:latest'
args '-u root:root'
}
}
stages {
stage('test') {
steps {
sh 'altwalker online tests -m models/model.json "random(vertex_coverage(100))" --report-xml'
junit 'report.xml'
}
}
}
}
For projects which require a more customized execution environment, Pipeline also supports building and running a container from a
Dockerfile
in the source repository.Copy one of the examples below into your repository and name it Dockerfile
:
FROM altwalker/altwalker:latest
# Install your specific requirements
Replace image 'altwalker/altwalker:latest'
with dockerfile true
from one of the previous example.
In contrast to the previous approach of using an "off-the-shelf" container, using the agent
{ dockerfile true }
syntax will build a new image from your Dockerfile
rather than pulling one from Docker Hub.For a python project the
Jenkinsfile
should look like this:pipeline {
agent {
docker {
dockerfile true
args '-u root:root'
}
}
stages {
stage('test') {
steps {
sh 'altwalker online tests -m model/default.json "random(vertex_coverage(100))"'
}
}
}
}
The agent
{ dockerfile true }
syntax supports a number of other options which are described in more detail in the Pipeline Syntax section.For a fully working example you can check out:
33