jenkins-declarative-pipeline

How to select multiple JDK version in declarative pipeline Jenkins

别说谁变了你拦得住时间么 提交于 2019-12-03 06:49:55
I want to use different JDK versions for different stages in Jenkins declarative pipeline. In the first stage I am using Java 8. In the second stage i am using Java 6. How to select multiple JDK version in declarative pipeline in Jenkins? pipeline { agent any tools { jdk 'jdk_1.8.0_151' jdk 'jdk_1.6.0_45' } stages { stage('java 8') { steps { sh 'java -version' sh 'javac -version' } } stage('java 6') { steps { sh 'java -version' sh 'javac -version' } } } } you can add a tools section for each stage. pipeline { agent any stages { stage ("first") { tools { jdk "jdk-1.8.101" } steps { sh 'java

How to create methods in Jenkins Declarative pipeline?

感情迁移 提交于 2019-11-29 23:53:08
In Jenkins scripted pipeline we are able to create methods and can call them. Is it possible also in the Jenkins declarative pipeline? And how? Newer versions of the declarative pipelines support this, while this was not possible before (~mid 2017). You can just declare functions as you'd expect it from a groovy script: pipeline { agent any stages { stage('Test') { steps { whateverFunction() } } } } void whateverFunction() { sh 'ls /' } You can create a groovy function like this and save it in your git which should be configured as managed library (Configure it in jenkins too): /path/to/repo

How to create methods in Jenkins Declarative pipeline?

前提是你 提交于 2019-11-28 20:54:15
问题 In Jenkins scripted pipeline we are able to create methods and can call them. Is it possible also in the Jenkins declarative pipeline? And how? 回答1: Newer versions of the declarative pipelines support this, while this was not possible before (~mid 2017). You can just declare functions as you'd expect it from a groovy script: pipeline { agent any stages { stage('Test') { steps { whateverFunction() } } } } void whateverFunction() { sh 'ls /' } 回答2: You can create a groovy function like this and

In a declarative jenkins pipeline - can I set the agent label dynamically?

你说的曾经没有我的故事 提交于 2019-11-27 14:37:19
Is there a way to set the agent label dynamically and not as plain string? The job has 2 stages: First stage - Runs on a "master" agent, always. At the end of this stage I will know on which agent should the 2nd stage run. Second stage - should run on the agent decided in the first stage. My (not working) attempt looks like this: pipeline { agent { label 'master' } stages { stage('Stage1') { steps { script { env.node_name = "my_node_label" } echo "node_name: ${env.node_name}" } } stage('Stage2') { agent { label "${env.node_name}" } steps { echo "node_name: ${env.node_name}" } } } } The first

In a declarative jenkins pipeline - can I set the agent label dynamically?

谁都会走 提交于 2019-11-26 16:53:12
问题 Is there a way to set the agent label dynamically and not as plain string? The job has 2 stages: First stage - Runs on a "master" agent, always. At the end of this stage I will know on which agent should the 2nd stage run. Second stage - should run on the agent decided in the first stage. My (not working) attempt looks like this: pipeline { agent { label 'master' } stages { stage('Stage1') { steps { script { env.node_name = "my_node_label" } echo "node_name: ${env.node_name}" } } stage(