📚 Cheatsheet

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

Snippets 8

Retour
Jenkins - Archiver des artifacts
Facile
steps {
    archiveArtifacts artifacts: 'build/app.jar', fingerprint: true
}
Jenkins - Conditions post-build
Facile
post {
    always {
        echo 'This will always run'
    }
    success {
        echo 'This will run only if successful'
    }
    failure {
        echo 'This will run only if failed'
    }
}
Jenkins - Paramètres de build
Intermédiaire
pipeline {
    agent any
    parameters {
        string(name: 'BRANCH', defaultValue: 'main', description: 'Branch to build')
    }
    stages {
        stage('Build') {
            steps {
                echo "Building branch ${params.BRANCH}"
            }
        }
    }
}
Jenkins - Pipeline avec approbation
Avancé
stage('Deploy to Prod') {
    steps {
        input 'Deploy to production?'
        echo 'Deploying...'
    }
}
Jenkins - Pipeline déclaratif simple
Facile
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
            }
        }
    }
}
Jenkins - Utiliser des credentials
Intermédiaire
environment {
    MY_SECRET = credentials('my-secret-id')
}
steps {
    sh 'echo $MY_SECRET'
}
Jenkins - Utiliser un agent Docker
Intermédiaire
pipeline {
    agent { docker { image 'node:18-alpine' } }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}
Jenkins - Utiliser une librairie partagée
Avancé
@Library('my-shared-library') _

pipeline { ... }