This tutorial should help you setup a CI/CD pipeline on Jenkins for your AltWalker tests.
Table Of Contents
- Create your first Pipeline
- Quick Start Examples
- Setup XML Reports
- Using a
Dockerfile
- Examples
- Resources
Create your first Pipeline
-
Copy one of the examples below into your repository and name it
Jenkinsfile
. Try modifying thesh
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!
Quick Start Examples
Below are some easily copied and pasted examples of a simple Pipeline for Python and .NET.
Python
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))"'
}
}
}
}
.NET
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
.
Setup XML Reports
After you setup for first pipeline:
To generate the XML reports add the
--report-xml
to youronline
orwalk
command.-
Inside the
Jenkinsfile
after theonline
orwalk
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'
}
}
}
}
Using a Dockerfile
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'
withdockerfile 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.
Examples
For a fully working example you can check out:
- for Python: https://github.com/Robert-96/altwalker-jenkins-example
- for .NET: https://github.com/Robert-96/altwalker-jenkins-dotnet-example
Top comments (0)