DEV Community

Thomas H Jones II
Thomas H Jones II

Posted on • Originally published at thjones2.blogspot.com on

Seriously, Jenkins?

Have I used that title before? I feel like I ask that question a lot when writing pipelines for Jenkins.

Today's bit of credulity-testing had to do with using the pipeline DSL's git directive. Prior to today, I'd been setting up Jenkins jobs to only deal with branches. Since the project I'm working on has a bit more complexity in its code-flow, I figured I'd try using release-tags instead of branching.

It, uh, didn't go well. Normally, when I'm using a branch-based approach, I'm able to get away with DSL that looks something like:

pipeline {

    agent any

    parameters {
        string(
            name: 'GitCred',
            description: 'Jenkins-stored Git credential with which to execute git commands'
        )
        string(
            name: 'GitProjUrl',
            description: 'SSH URL from which to download the git project contents'
        )
        string(
            name: 'GitProjBranch',
            description: 'Project-branch to use from the git project'
        )
    }

    stages {
        stage ('Prep Work Environment') {
            steps {
                deleteDir()
                git branch: "${GitProjBranch}",
                    credentialsId: "${GitCred}",
                    url: "${GitProjUrl}"

[...elided...]

Unfortunately, when you want to use tags the invocation is a bit more pedantic (and the documentation is maddenly obtuse in trying to find this juju):

[...elided...]
    stages {
        stage ('prep Work Environment') {
            steps {
                deleteDir()
                checkout scm: [
                    $class: 'GitSCM',
                    userRemoteConfigs: [
                        [
                            url: "${GitProjUrl}",
                            credentialsId: "${GitCred}"
                        ]
                    ],
                    branches: [
                        [
                            name: "${GitProjBranch}"
                        ]
                    ]
                ],
                poll: false
[...elided...]

It was where, having switched to this form and my job started working that I loudly uttered, "seriously, Jenkins??". My cube-mates love me.

On the plus side, while my original invocation works only for branches, the more-pedantic invocation works for both branches and tags.

Latest comments (0)