📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 5

Retour
Appeler une fonction d'une librairie partagée
Intermédiaire
@Library('my-shared-library') _

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                standardMavenBuild(goal: 'clean install')
            }
        }
    }
}
Déclarer une librairie partagée
Intermédiaire
@Library('my-shared-library') _

pipeline { /* ... */ }
Importer une classe d'une librairie partagée (src)
Avancé
// src/com/example/Utils.groovy
package com.example

class Utils {
    static void sayHello(script) {
        script.echo 'Hello from shared lib!'
    }
}
Structure d'une librairie partagée (vars)
Avancé
// vars/standardMavenBuild.groovy
def call(Map config) {
    sh "mvn ${config.goal}"
}
Utiliser une classe d'une librairie partagée
Avancé
@Library('my-shared-library')
import com.example.Utils

node {
    stage('Demo') {
        Utils.sayHello(this)
    }
}