Is there a way of cloning the repo an additional layer down?

40 views
Skip to first unread message

dandeliondodgeball

unread,
Oct 2, 2017, 3:13:02 PM10/2/17
to Jenkins Users
Default: ../workspace/Pipeline01/<what ever you clone>
Desired: ../workspace/Pipeline01/repo01code/<what ever you clone>

Why do I want to do this?   
The scripts to build the code, can't live at the same level as the code.  I can have the scripts live some place other then the Pipeline01 workspace, but then Jenkins doesn't "know" about them.

Assuming there is no simple generic solution, what is the best custom solution?  My first thought would be a script.

Thanks.

Daniel Beck

unread,
Oct 2, 2017, 3:16:45 PM10/2/17
to Jenkins Users

> On 2. Oct 2017, at 21:13, dandeliondodgeball <chris...@3derm.com> wrote:
>
> Assuming there is no simple generic solution, what is the best custom solution? My first thought would be a script.
>

If this is a scripted pipeline, you can do

dir('repo01code') {
checkout scm
}

dandeliondodgeball

unread,
Oct 6, 2017, 4:24:31 PM10/6/17
to Jenkins Users
Did this two different ways in the same workspace. 
../workspace/Pipeline01/Artifact/my.zip
../workspace/Pipeline01/clonedRepo/

One for the artifact I needed.   
For this I used an attribute in the CopyArtifact plugin, like this (declarative pipeline):
stages {
    stage('Copy Archive') {
        steps {
            script {
                step ([$class: 'CopyArtifact',
                projectName: 'Create_archive',
                filter: "packages/my.zip",
                target: 'Artifact']);



And another for the code which was getting cloned.   
For this I used the "Check out to sub-directory" feature in the git plugin, like this:



Mark Waite

unread,
Oct 6, 2017, 5:06:33 PM10/6/17
to jenkins...@googlegroups.com
If you use the dir('dest-dir') { checkout scm } syntax, you avoid using that special case from the git plugin, and have something that is maintained in code (and looks like pipeline), rather than something that looks like a special case of the git plugin.

The technique you used (with the git extension) works, but was really created to be used with freestyle projects.  Pipeline has a better way to do it with the dir() step.

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/f6b55274-4823-47e3-b1a7-46892e9d3601%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Foran

unread,
Oct 9, 2017, 3:46:47 PM10/9/17
to jenkins...@googlegroups.com
Good point.  I would rather have it in the Jenkinsfile.  Thanks.

On Fri, Oct 6, 2017 at 5:06 PM, Mark Waite <mark.ea...@gmail.com> wrote:
On Fri, Oct 6, 2017 at 2:24 PM dandeliondodgeball <chris...@3derm.com> wrote:
Did this two different ways in the same workspace. 
../workspace/Pipeline01/Artifact/my.zip
../workspace/Pipeline01/clonedRepo/

One for the artifact I needed.   
For this I used an attribute in the CopyArtifact plugin, like this (declarative pipeline):
stages {
    stage('Copy Archive') {
        steps {
            script {
                step ([$class: 'CopyArtifact',
                projectName: 'Create_archive',
                filter: "packages/my.zip",
                target: 'Artifact']);



And another for the code which was getting cloned.   
For this I used the "Check out to sub-directory" feature in the git plugin, like this:




If you use the dir('dest-dir') { checkout scm } syntax, you avoid using that special case from the git plugin, and have something that is maintained in code (and looks like pipeline), rather than something that looks like a special case of the git plugin.

The technique you used (with the git extension) works, but was really created to be used with freestyle projects.  Pipeline has a better way to do it with the dir() step.

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-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/ZlxbJHRC2Dg/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAO49JtG_t7%2BvdWK0P1qovNV5zX7J71UEfoWsCxXkHaM8TZH%3D1A%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Chris Foran       | Senior Software Engineer
(617) 586-9962 | chris...@3Derm.com 

101 Huntington Ave, 17th Floor
Suite 1300 c/o 3Derm @ BCBSMA
Boston, MA 02199

itchymuzzle

unread,
Nov 1, 2017, 4:36:16 PM11/1/17
to Jenkins Users
If you use the dir('dest-dir') { checkout scm } syntax, you avoid using that special case from the git plugin, and have something that is maintained in code (and looks like pipeline), rather than something that looks like a special case of the git plugin.

This works, but the code is cloned twice.  Once in the workspace, then again into the sub directory defined by dir('dest-dir'), in the same workspace.  I assume there is no way around this, as Jenkinsfile needs to be found, to be able to use it.  But I figured I would ask.  Thanks.

Mark Waite

unread,
Nov 1, 2017, 5:24:31 PM11/1/17
to jenkins...@googlegroups.com
On Wed, Nov 1, 2017 at 2:36 PM itchymuzzle <chris...@3derm.com> wrote:
If you use the dir('dest-dir') { checkout scm } syntax, you avoid using that special case from the git plugin, and have something that is maintained in code (and looks like pipeline), rather than something that looks like a special case of the git plugin.

This works, but the code is cloned twice.  Once in the workspace, then again into the sub directory defined by dir('dest-dir'), in the same workspace.  I assume there is no way around this, as Jenkinsfile needs to be found, to be able to use it.  But I figured I would ask.  Thanks.

If you use one of the more advanced branch sources (GitHub or Gitea or possibly Bitbucket), I believe they use a different technique to read the Jenkinsfile.  That different technique does not require a full clone of the repository.

Stephen Connolly has a series of "live coding" blog posts which show his work on the Apache Maven project which may lead to additional ways of avoiding the full clone to obtain the Jenkinsfile.  Refer to https://www.cloudbees.com/blog/watch-me-code-episode-1 

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/b9acde7c-a050-4b6b-8979-c97a51633959%40googlegroups.com.

itchymuzzle

unread,
Nov 2, 2017, 9:58:42 AM11/2/17
to Jenkins Users
Helpful, as always, thanks.  I will take a look at that.
Reply all
Reply to author
Forward
0 new messages