I wanted to translate some jobs to the new Jenkins 2.0 declarative pipelines. At the moment they are 3 different jobs:
- CI --> PollSCM every 5 min (only master), build and run tests.
- NIghtly --> Run every night (build, test, integration test and deploy on nightly server)
- Sprintly --> It is a parameterized job that runs with manually created tags every Thursday. (build, test, integration test and deploy on sprintly server)
For this purpose, I have a small project in spring with maven that will be the best example for me to start (Simple, easy and fast to be built).
At the moment I have already a Multibranch pipeline for the CI build but I want to integrate into this job a Nightly and Sprintly build.
- Nightly: Run a Cron job on the night over the master branch to be deployed in Nightly Server.
- Sprintly: Be build over a Sprintly_tag generated by me in the master branch to be deployed in Sprintly Server.
At the moment I have this JenkinsFile
pipeline {
agent {
label 'master'
}
tools {
maven "Apache Maven 3.3.9"
jdk "Java JDK 1.8 U102"
}
triggers {
cron ('H(06-08) 01 * * *')
pollSCM('H/5 * * * *')
}
stages {
stage('Build') {
steps {
sh 'mvn -f de.foo.project.client/ clean package'
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml'
archiveArtifacts allowEmptyArchive: true, artifacts: '**/target/*.war'
}
}
}
stage('Deploy') {
sh 'echo "Deploy only master"'
}
}
It runs every branch when something is pull to Git and also Run around 1 oclock in the night (but still running all the branches).
Any idea or hint to do that? The code to do the deployment is not required I only want to know how to filter/split this branches being in the same JenkinsFile
Many thanks to all!
Edit: I can also use but It will run all the branches in the night (can I made this filter only for the Cron job?)
stage('DeployBranch') {
when { branch 'story/RTS-525-task/RTS-962'}
steps {
sh 'echo "helloDeploy in the branch"'
}
}
stage('DeployMaster') {
when { branch 'master'}
steps {
sh 'echo "helloDeploy in the master"'
}
}