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

Leave a Comment

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