Making static helper method for GIT. But can't make it work correctly in a MULTISCM block.

652 views
Skip to first unread message

Taras Fog

unread,
Nov 24, 2016, 4:06:35 PM11/24/16
to job-dsl-plugin
Hi guys,

I am doing static helpers for decreasing the complexity of my DSL-seed jobs.

But have just came to the point where I can't overcome the issue.

Here is static method:

//MultiSCMGit static method:
static MultiSCMGit(Job job, String URLValue, String credentialsValue, String branchValue, String relativeTargetDirectoryValue) {
job.with {
multiscm {
git {
remote {
url(URLValue)
credentials(credentialsValue)
}
branch(branchValue)
extensions {
relativeTargetDirectory(relativeTargetDirectoryValue)
}
}
}
}
}

And here how I call it. I need from time to time 2 or 3 GIT blocks in MULTISCM:

def newJob = job("$JobName")
//section for source control management system:
MultiSCMGit(newJob, 'g...@bitbucket.org:something.git', GitBitBucketKeyIdNumber, '*/master', 'scripts')
MultiSCMGit(newJob, 'g...@bitbucket.org:something_more.git', GitDeploymentKeyIdNumber, '${Commit}', 'sources')

As the result, I get only last block. As far as I understand it just uses full MULTISCM block which one was used last.
I can't figure out how to make it just add two GIT blocks into MULTISCM.

Any help or an advice is much appreciated.

Regards,
Taras.

Daniel Spilker

unread,
Dec 3, 2016, 9:18:48 AM12/3/16
to job-dsl...@googlegroups.com
The scm and multiscm configuration is always replaced as a whole. You can not append an scm config to multiscm context. Instead you need to specify all scm configs within a single multiscm block as shown in this example: https://jenkinsci.github.io/job-dsl-plugin/#path/job-multiscm

But you can use a loop to construct several scm configs with a multiscm context:

def configs = [
    [url: 'one', creds: 'two'],
    [url: 'three', creds: 'four'],
]
                  

job('example') {
    multiscm {
        configs.each { config ->
            git {
                remote {
                    url(config.url)
                    credentials(config.creds)
                }
            }
        }
    }
}

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/7b76d9e2-c260-4186-8d96-3e085cf67f90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages