How to copy a folder one location to another location via jenkins.instance groovy scripts

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to copy a folder one location to another location via jenkins.instance groovy scripts

Ramesh Mari
Hello guys,
This task might have one challenge to you, the question is simple but the implications is very tricky.  Please refer the below questions.

Requirements - jenkins groovy scripts
Folder copy one location to another location via jenkins.instance.  There is method call items.move it does cut and paste, that same i need copy and paste.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8a709eda-772c-435d-839a-bebde442e365%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

How to copy a folder one location to another location via jenkins.instance groovy scripts

James Nord-2
this is not as simple as it sounds.

first off a disclaimer CloudBees (my employer) as a proprietary feature that does this.

the reason it is not simple is each job type may have special folders.  then you have builds which again may have artifacts may have special files etc etc...  trust me there is a lot of edge cases.

if you can simplify things (if the source has builds the destination will have the same builds) then you can do some tricks copying in the same Jenkins instance.
firstly the job structure is *normally* job/name so you can recursively copy the folder job/foldername.  to job/dest/job/folder name

then you need to tell the parent it has a new child by loading the XML https://javadoc.jenkins.io/jenkins/model/ModifiableTopLevelItemGroup.html#createProjectFromXML-java.lang.String-java.io.InputStream-

alternatively you can copy the jobs recursively
 https://javadoc.jenkins.io/jenkins/model/ModifiableTopLevelItemGroup.html#copy-T-java.lang.String-

or you could become a customer of cloudbees :)

you could possibly also somehow use jobDSL with the seed jobs (but I have never used that)

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c586b3e0-8fa5-4d6e-9251-954a288af9a3%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to copy a folder one location to another location via jenkins.instance groovy scripts

Ramesh Mari
Hi James, 

I tried all the way what you have mentioned, but it only copy the job alone without build history and also the copied job as non-build able for that we need to trigger save function additionally.  I raised a ticket to cloudbees they only give support for subscription.   can you raise a ticket if possible. 

On Thursday, November 14, 2019 at 5:33:31 AM UTC+5:30, James Nord wrote:
this is not as simple as it sounds.

first off a disclaimer CloudBees (my employer) as a proprietary feature that does this.

the reason it is not simple is each job type may have special folders.  then you have builds which again may have artifacts may have special files etc etc...  trust me there is a lot of edge cases.

if you can simplify things (if the source has builds the destination will have the same builds) then you can do some tricks copying in the same Jenkins instance.
firstly the job structure is *normally* job/name so you can recursively copy the folder job/foldername.  to job/dest/job/folder name

then you need to tell the parent it has a new child by loading the XML <a href="https://javadoc.jenkins.io/jenkins/model/ModifiableTopLevelItemGroup.html#createProjectFromXML-java.lang.String-java.io.InputStream-" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjavadoc.jenkins.io%2Fjenkins%2Fmodel%2FModifiableTopLevelItemGroup.html%23createProjectFromXML-java.lang.String-java.io.InputStream-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHfyBh-IbD8xIT7ufYhuqlmv9ZCWw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjavadoc.jenkins.io%2Fjenkins%2Fmodel%2FModifiableTopLevelItemGroup.html%23createProjectFromXML-java.lang.String-java.io.InputStream-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHfyBh-IbD8xIT7ufYhuqlmv9ZCWw&#39;;return true;">https://javadoc.jenkins.io/jenkins/model/ModifiableTopLevelItemGroup.html#createProjectFromXML-java.lang.String-java.io.InputStream-

alternatively you can copy the jobs recursively
 <a href="https://javadoc.jenkins.io/jenkins/model/ModifiableTopLevelItemGroup.html#copy-T-java.lang.String-" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjavadoc.jenkins.io%2Fjenkins%2Fmodel%2FModifiableTopLevelItemGroup.html%23copy-T-java.lang.String-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFbV_dqzjl3FrDeeO-9uGjDC3pz5g&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjavadoc.jenkins.io%2Fjenkins%2Fmodel%2FModifiableTopLevelItemGroup.html%23copy-T-java.lang.String-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFbV_dqzjl3FrDeeO-9uGjDC3pz5g&#39;;return true;">https://javadoc.jenkins.io/jenkins/model/ModifiableTopLevelItemGroup.html#copy-T-java.lang.String-

or you could become a customer of cloudbees :)

you could possibly also somehow use jobDSL with the seed jobs (but I have never used that)

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/21a183fd-839b-4474-aec5-3103ed7a6263%40googlegroups.com.