Hinson's blog

𝕰𝖝𝖈𝖊𝖑𝖑𝖊𝖓𝖈𝖊 𝖎𝖓 𝖈𝖑𝖔𝖚𝖉 𝖆𝖗𝖈𝖍𝖎𝖙𝖊𝖈𝖙𝖚𝖗𝖊 𝖆𝖓𝖉 𝖘𝖊𝖈𝖚𝖗𝖎𝖙𝖞 𝖉𝖔𝖒𝖆𝖎𝖓𝖘 𝖎𝖘 𝖙𝖍𝖊 𝖊𝖙𝖊𝖗𝖓𝖆𝖑 𝖕𝖚𝖗𝖘𝖚𝖎𝖙 𝖔𝖋 𝖒𝖞 𝖕𝖗𝖔𝖋𝖊𝖘𝖘𝖎𝖔𝖓𝖆𝖑 𝖌𝖗𝖔𝖜𝖙𝖍

Dive into Services Glue: The Syntax of Jenkinsfile in Details

Spread the love

Reference document: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/


  • The Central Hub: The Jenkins Controller acts as the central management point for the Jenkins environment. It is responsible for scheduling jobs, orchestrating workflows, managing configurations, and maintaining the overall state of the CI/CD pipeline. It also provides the user interface for users to interact with Jenkins.
  • Delegation of Work: Although the Controller can execute jobs, in a distributed setup, its primary role is to delegate work to Jenkins Agents. This approach allows the Controller to focus on management tasks without being overloaded by job execution.

  • Executors of Jobs: Jenkins Agents are responsible for executing the jobs assigned to them by the Controller. An agent can be a physical machine, a virtual machine, or a containerized environment that runs build tools and environments necessary for job execution.
  • Scalability and Flexibility: By using multiple agents, Jenkins can scale beyond the limitations of a single server, handling multiple builds and tasks concurrently. Agents can be specialized for different types of jobs, depending on the tools and environments they provide, allowing for a flexible and optimized build process.


  • archiveArtifacts captures the files built matching the include pattern (*/target/.jar) and saves them to the Jenkins controller for later retrieval.
  • artifacts: Specifies the files to archive. You can use wildcards to include multiple files.
  • fingerprint: When set to true, Jenkins will fingerprint the artifacts, enabling tracking of which builds produced which artifacts. This is useful for traceability and for identifying which build an artifact came from.


junit step

pipeline {
    agent any

    stages {
        stage('Test') {
            steps {
                /* `make check` returns non-zero on test failures,
                * using `true` to allow the Pipeline to continue nonetheless
                */
                sh 'make check || true'
                junit '**/target/*.xml'
            }
        }
    }
}




https://automation.hinsonli.com/pipeline-syntax/globals



pipeline {
    agent any
    environment {
        CC = 'clang'
    }
    stages {
        stage('Example') {
            environment {
                DEBUG_FLAGS = '-g'
            }
            steps {
                sh 'printenv'
            }
        }
    }
}
  • An environment directive used in the top-level pipeline block will apply to all steps within the Pipeline.
  • An environment directive defined within a stage will only apply the given environment variables to steps within the stage.


pipeline {
    agent any
    environment {
        // Using returnStdout
        CC = """${sh(
                returnStdout: true,
                script: 'echo "clang"'
            )}"""
        // Using returnStatus
        EXIT_STATUS = """${sh(
                returnStatus: true,
                script: 'exit 1'
            )}"""
    }
    stages {
        stage('Example') {
            environment {
                DEBUG_FLAGS = '-g'
            }
            steps {
                sh 'printenv'
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *