This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Custom tools | |
// | |
import com.cloudbees.jenkins.plugins.customtools.CustomTool | |
import hudson.tools.InstallSourceProperty | |
import hudson.tools.ZipExtractionInstaller | |
def tools = Jenkins.instance.getDescriptorByType(CustomTool.DescriptorImpl.class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check for early exit of a pipeline. The env check has to be inside a node. | |
boolean earlyExit = false | |
node { | |
echo "env.PIPE_DISABLED = ${env.PIPE_DISABLED}" | |
if(env?.PIPE_DISABLED == 'true') { | |
earlyExit = true | |
} | |
} | |
if(earlyExit) { | |
echo "Early exit pipeline as disabled" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First pipeline declaration | |
pipeline { | |
// Run on any node | |
agent label: "" | |
stages { | |
stage('Section 1') { | |
steps { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent label: "" | |
stages { | |
stage('Bar') { | |
steps { | |
script { | |
helloTest { | |
message = "hello this is a test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
environment { | |
FOO_OUT = "Foo" | |
} | |
agent label:"LNX64" | |
wrappers { | |
timestamps() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* How to Unit test Spring Boot REST Controller with mocks | |
* | |
* Requires Groovy mockito support dependency in build.gradle: | |
* | |
* testCompile("org.springframework.boot:spring-boot-starter-test") | |
* | |
* Otherwise mocks crash with NPE.. | |
* See https://github.com/cyrusinnovation/mockito-groovy-support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name of the matrix job to configure | |
def jobName = 'MATRIX' | |
// Get the matrix job | |
def job = hudson.model.Hudson.instance.getItem(jobName) | |
assert job != null, "The job $jobName could not be found" | |
// Check it is a matrix job | |
assert job.getClass() == hudson.matrix.MatrixProject.class, "The job $jobName is of class '${job.getClass().name}', but expecting 'hudson.matrix.MatrixProject'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// System groovy script to correlate upstream jobs on a parameter value matching a parameter value on this job | |
// | |
// - Have 1 - N upstream jobs which are called externally with a parameter "FOO" | |
// - The upstream jobs each call this job with the same parameter "FOO" | |
// - In this job, I want to continue some process when "FOO" has the same value for any builds of the upstream jobs | |
// - Hence correlating on the FOO parameter value | |
// - I don't want to look back too many builds on the upstream jobs | |
// How many builds to look back on. Set to zero for all builds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upStreamProjects = build.getParent().getUpstreamProjects() | |
println "Found ${upStreamProjects.size()} upstream projects" | |
upStreamProjects.each { p -> println "upstream project: ${p.getName()}" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.cli.CLI | |
buildscript { | |
repositories { | |
maven { | |
url 'http://repo.jenkins-ci.org/repo/' | |
} | |
} | |
dependencies { | |
classpath 'org.jenkins-ci.main:cli:1.519' |
NewerOlder