Checkout from multiple SCMs/repos in declarative pipeline?

3,062 views
Skip to first unread message

Kirill Peskov

unread,
Jun 7, 2017, 11:36:30 AM6/7/17
to Jenkins Users
Hi All,

Due to some project restrictions I have to combine sources from 3
repositories (1 Subversion and 2 Git repos), is there an easy way to
achieve that in a declarative pipeline? Neither project subdirs nor
files in the root of each repo are not overlapping with each other, so
merging them in one workspace is actually safe.

Something like that:

pipeline {
agent {
dockerfile { dir 'ubuntu-xenial-mysql' }

}
stages {
stage('Sources & Additional Tools Checkout'){
steps {
svn url:'url-to-installer-sources'
git url:'url-to-test-tools'
git url:'url-to-packager-sources'
}
}
stage('Test suite') {
steps {
// Do some tests ...
}
stage('Build the package') {
steps {
// Invoke deb-package builder ...
}

}

I've tested the simplified version of it trying to combine 2 GIT repos,
it didn't work, second 'git' step wipes everything out of workspace...


Cheers,

Kirill

Kirill Peskov

unread,
Jun 8, 2017, 3:14:20 AM6/8/17
to jenkins...@googlegroups.com

Currently, as the test tools and debian packager are significantly smaller than main source code I could probably stash/unstash their corresponding subfolders to achieve the necessary effect, but it doesn't look elegant... ;)

//...
git url:'url-to-packager-sources'

stash name: "debian-installer", includes: "debian/*"
git url:'url-to-test-tools'

stash name: "test-tools", includes: "test-tools/*"
svn url:'url-to-installer-sources'

unstash "debian-installer"
unstash "test-tools"
//...

Cheers,
Kirill

Christopher Orr

unread,
Jun 8, 2017, 7:42:33 AM6/8/17
to jenkins...@googlegroups.com
I'm not sure exactly what the `git` step does, but you could try using
the `checkout` step instead.

Kirill Peskov

unread,
Jun 8, 2017, 11:55:13 AM6/8/17
to jenkins...@googlegroups.com
steps 'git' and 'svn' are actually shortcuts for checkout step with
corresponding $class.

The problem is, that $class: 'GitSCM' does not accept parameter local: ,
so it checks everything out to the workspace root anyway, promptly
wiping out results of previous step... Looks like there is workaround
possible, using

extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir:
"foo_bar_dir"]

I'll try that, will see if it works...

Cheers,
Kirill

Mark Waite

unread,
Jun 8, 2017, 12:02:55 PM6/8/17
to jenkins...@googlegroups.com
The scripted pipeline has a dir() and a ws() command which can be used as a wrapper around a checkout.  I haven't looked to see if the same is available in declarative.

I'd prefer that the git plugin "checkout to subdirectory" not be used in pipeline, since there is already a concept for creating subdirectories in pipeline, without relying on a special option of one SCM.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/faeb80c4-1f50-a1c7-35c5-682bec448a77%40paranoid.email.
For more options, visit https://groups.google.com/d/optout.

Andrew Bayer

unread,
Jun 8, 2017, 2:02:34 PM6/8/17
to jenkins...@googlegroups.com
Yeah, you can use something like 
stages {
  stage("foo") {
    steps {
      dir("some-dir") {
        checkout ...
      }
   }
}

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtHQOR1QmWMpHFWYMLfMYm%3DryTk8csL%2BGAwC7ywqq4SmWg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages