Posts

Showing posts with the label Jenkins Pipeline

"Build Periodically" With A Multi-branch Pipeline In Jenkins

Answer : If you use a declarative style Pipeline and only want to trigger the build on a specific branch you can do something like this: String cron_string = BRANCH_NAME == "master" ? "@hourly" : "" pipeline { agent none triggers { cron(cron_string) } stages { // do something } } Found on Jenkins Jira If you are using a declarative style Jenkinsfile then you use the triggers directive. pipeline { agent any triggers { cron('H 4/* 0 0 1-5') } stages { stage('Example') { steps { echo 'Hello World' } } } } I was able to find an example illustrating this an discarding old builds, which is also something I wanted. Jenkinsfile in jenkins-infra/jenkins.io: properties( [ [ $class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '10'] ], ...

Can I Define Multiple Agent Labels In A Declarative Jenkins Pipeline?

Answer : You can see the 'Pipeline-syntax' help within your Jenkins installation and see the sample step "node" reference. You can use exprA||exprB : node('small||medium') { // some block } This syntax appears to work for me: agent { label 'linux && java' } EDIT: I misunderstood the question. This answer is only if you know which specific agent you want to run for each stage. If you need multiple agents you can declare agent none and then declare the agent at each stage. https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents From the docs: pipeline { agent none stages { stage('Build') { agent any steps { checkout scm sh 'make' stash includes: '**/target/*.jar', name: 'app' } } stage('Test on Linux') { agent { label ...