How do you load a groovy file and execute it

If your Jenkinsfile and groovy file in one repository and Jenkinsfile is loaded from SCM you have to do: Example.Groovy def exampleMethod() { //do something } def otherExampleMethod() { //do something else } return this JenkinsFile node { def rootDir = pwd() def exampleModule = load “${rootDir}@script/Example.Groovy ” exampleModule.exampleMethod() exampleModule.otherExampleMethod() }

How to create methods in Jenkins Declarative pipeline?

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 /’ }

Get absolute path to workspace directory in Jenkins Pipeline plugin

Since version 2.5 of the Pipeline Nodes and Processes Plugin (a component of the Pipeline plugin, installed by default), the WORKSPACE environment variable is available again. This version was released on 2016-09-23, so it should be available on all up-to-date Jenkins instances. Example node(‘label’){ // now you are on slave labeled with ‘label’ def workspace … Read more

Using a Jenkins pipeline to checkout multiple git repos into same job

You can use the dir command to execute a pipeline step in a subdirectory: node(‘ATLAS && Linux’) { dir(‘CalibrationResults’) { git url: ‘https://github.com/AtlasBID/CalibrationResults.git’ } dir(‘Combination’) { git url: ‘https://github.com/AtlasBID/Combination.git’ } dir(‘CombinationBuilder’) { git url: ‘https://github.com/AtlasBID/CombinationBuilder.git’ } sh(‘ls’) sh(‘. CombinationBuilder/build.sh’) }

How to write Pipeline to discard old builds?

As for declarative syntax, you can use the options block: pipeline { options { buildDiscarder(logRotator(numToKeepStr: ’30’, artifactNumToKeepStr: ’30’)) } … } Parameters for logRotator (from the source code): daysToKeepStr: history is only kept up to this days. numToKeepStr: only this number of build logs are kept. artifactDaysToKeepStr: artifacts are only kept up to this days. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)