Jenkins Pipeline : How could I access the git repository cloned at job start

2,782 views
Skip to first unread message

Jean-Luc Pinardon

unread,
Nov 29, 2016, 4:14:03 AM11/29/16
to Jenkins Users
Dear all,

I am exploring pipeline features, and I fall into a problem.
The repository is indeed correctly cloned at job start and the "jenkinsfile" is run.
But I "discover" that I cannot access the cloned files from within the stages within nodes. Just because, the workspace used at job begin is certainly not the same as the workspace within the nodes.

So, my question is : is there a way to make available the initially cloned files all over the pipeline, or should I clone the repository once more within the first stage and then stash the files I need.

Thanks for your help.
J.L.P.

nicolas de loof

unread,
Nov 29, 2016, 4:18:29 AM11/29/16
to jenkins...@googlegroups.com
by pipeline design, you need to define node usage (so workspace) and how long same node has to be used to run your build. This allows to distribute the build steps on multiple nodes (including parallel execution). For simplest scenario, you can just wrap the whole pipeline with a `node() { }` block.



--
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/067b2647-bb7a-44c6-81ca-5fa2afa1290d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jean-Luc Pinardon

unread,
Nov 29, 2016, 4:36:17 AM11/29/16
to Jenkins Users
Well, it seems that I  have not been clear enough...
My problem is at the very begining of the job, when the jenkinsfile (and... I thought... possibly other files from the repository) is cloned :


I clearly understand that the clone is made on a workspace that is (for sure) not the same as the first workspace when the first node block is used.
So, my question is :
Is there a way to access this early workspace to stash the files (or some of) within in order to use it in the pipeline ?


J.L.P.

Jean-Luc Pinardon

unread,
Nov 29, 2016, 5:19:12 AM11/29/16
to Jenkins Users
An additional question related with the current one is how to propagate a set of env var read from a property file ?
In other words, how to have a withEnv equivalent with a property file content.


J.L.P.

Le mardi 29 novembre 2016 10:14:03 UTC+1, Jean-Luc Pinardon a écrit :

Sam K

unread,
Dec 3, 2016, 1:37:31 AM12/3/16
to Jenkins Users
I just use a ws('<some predetermined space>') {
   git url:..... , branch: 'master'
}

and now all the cloned content is within the directory I want.  

Jean-Luc Pinardon

unread,
Dec 5, 2016, 3:05:43 AM12/5/16
to jenkins...@googlegroups.com
Hello,

Thanks for your answer.
But I am not sure to understand.
Where do you put this ws step ?
I am not sure to have been clear enough.
My concern is how to benefit from the SCM schedule and checkout phase made to retrieve the so called jenkinsfile, i.e. the script (and possible libraries) that is executed to run the pipeline.

--
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/qzBWmFHOmoI/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/aca57995-52c2-42f6-94aa-5cee7e434b29%40googlegroups.com.

Christoph Nenning

unread,
Dec 5, 2016, 3:31:11 AM12/5/16
to jenkins...@googlegroups.com
Hi,


> Where do you put this ws step ?

You can put it at the beginning of your Jenkinsfile


> My concern is how to benefit from the SCM schedule and checkout
> phase made to retrieve the so called jenkinsfile, i.e. the script
> (and possible libraries) that is executed to run the pipeline.


AFAIK you cannot use the workspace that jenkins creates to checkout Jenkinsfile.

But you can checkout the same repo (or other polled SCM URLs) with this command:

checkout scm


Regards,
Christoph
> jenkinsci-use...@googlegroups.com.

> To view this discussion on the web visit
https://groups.google.com/

> d/msgid/jenkinsci-users/aca57995-52c2-42f6-94aa-5cee7e434b29%
> 40googlegroups.com.

>
> For more options, visit
https://groups.google.com/d/optout.
>
> --
> 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/CALijN65Q_TE2zj5NhwJpoi5%2BW3jX-
> vVXds0QVJrXO4iKs72Wkw%40mail.gmail.com.
> For more options, visit
https://groups.google.com/d/optout.


This Email was scanned by Sophos Anti Virus

Jean-Luc Pinardon

unread,
Dec 5, 2016, 3:46:43 AM12/5/16
to jenkins...@googlegroups.com
Hi, Chritoph Nenning,

Thanks for your answer.

>AFAIK you cannot use the workspace that jenkins creates to checkout Jenkinsfile.

So, it means as you say after, that I need to checkout agoin files I already checked out just before.
That's what I wanted to avoid. Simply because I don't like to do twice the same thing.
So, as far as this behavior seems confirmed, and we want to avoid repeating things, it means that an effort must be made on scm repository side to clearly separate things that are yet related.
It is not a so big deal.
On the other hand, the volume of data involved here are not so big. It should not have a noticeable impact on the whole pipeline process, and thus the question is perhaps finally more a matter of principle. There should be no heavy consequences as far as things are correctly done on SCM repository side.

Again, thanks for your help.
Have a nide day.
J.L.P.




> To view this discussion on the web visit

> d/msgid/jenkinsci-users/aca57995-52c2-42f6-94aa-5cee7e434b29%
> 40googlegroups.com.

>
> For more options, visit
https://groups.google.com/d/optout.
>
> --
> 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,

> To view this discussion on the web visit

> d/msgid/jenkinsci-users/CALijN65Q_TE2zj5NhwJpoi5%2BW3jX-
> vVXds0QVJrXO4iKs72Wkw%40mail.gmail.com.
> For more options, visit
https://groups.google.com/d/optout.


This Email was scanned by Sophos Anti Virus

--
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/qzBWmFHOmoI/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/OFE7E55BA0.1AC16254-ONC1258080.002E9363-C1258080.002EBDB0%40lex-com.net.

nicolas de loof

unread,
Dec 5, 2016, 4:34:26 AM12/5/16
to jenkins...@googlegroups.com
the Jenkinsfile detection indeed relies on a git clone on master, but this isn't considered a workspace. Also, it might not be necessary for some integrations, typically one could access this specific file remotely (not sure about the actual implementation)

To get the exact commit that triggered a build, your Jenkinsfile should look like :

node() {
   checkout scm
   ...
}



2016-12-05 9:30 GMT+01:00 Christoph Nenning <Christop...@lex-com.net>:

> To view this discussion on the web visit

> d/msgid/jenkinsci-users/aca57995-52c2-42f6-94aa-5cee7e434b29%
> 40googlegroups.com.

>
> For more options, visit
https://groups.google.com/d/optout.
>
> --
> 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,

> To view this discussion on the web visit

> d/msgid/jenkinsci-users/CALijN65Q_TE2zj5NhwJpoi5%2BW3jX-
> vVXds0QVJrXO4iKs72Wkw%40mail.gmail.com.
> For more options, visit
https://groups.google.com/d/optout.


This Email was scanned by Sophos Anti Virus

--
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/OFE7E55BA0.1AC16254-ONC1258080.002E9363-C1258080.002EBDB0%40lex-com.net.

Jean-Luc Pinardon

unread,
Dec 5, 2016, 4:46:29 AM12/5/16
to jenkins...@googlegroups.com
Hi,

Thanks a lot for the explanation.
In fact, I must come back to the very first reason of my question.
My concern is that the jenkinsfile, so the pipeline, is supposed to be executed by taking first into account a property file that will be used to configure the whole build chain.  So it seemed very natural to checkout the jenkinsfile and its property file along with to set up the environment of the pipeline. That would perhaps be an interesting feature...

Thanks for your help
J.L.P.

Reply all
Reply to author
Forward
0 new messages