Can I load a declarative Jenkinsfile via a shared library?

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

Can I load a declarative Jenkinsfile via a shared library?

Idan Adar
Is the following feasible?

1. Setup a Shared Library in the Jenkins settings
2. In every repository requiring the Jenkinsfile (it is the same one used in multiple repos...), use the following in the Jenkinsfile of the repository instead:

(based on https://dev.to/jalogut/centralise-jenkins-pipelines-configuration-using-shared-libraries)

@Library("my-shared-library") _
    standardPipeline
{
       
// properties passed to the shared library
   
}

3. In the Shared Library, use this: 

def call(body) {
 
def config = [:]
  body
.resolveStrategy = Closure.DELEGATE_FIRST
  body
.delegate = config
  body
()

  pipeline
{
     
// the declarative pipeline as-is as it was previously used in a Jenkinsfile in a repository
 
}
}

--
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/c878f51d-8097-43fb-a0f5-a95b471f0184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can I load a declarative Jenkinsfile via a shared library?

Daniel Butler
I believe this was added a month or two ago.

On 10 Jan 2018 6:33 pm, "Idan Adar" <[hidden email]> wrote:
Is the following feasible?

1. Setup a Shared Library in the Jenkins settings
2. In every repository requiring the Jenkinsfile (it is the same one used in multiple repos...), use the following in the Jenkinsfile of the repository instead:


@Library("my-shared-library") _
    standardPipeline
{
       
// properties passed to the shared library
   
}

3. In the Shared Library, use this: 

def call(body) {
 
def config = [:]
  body
.resolveStrategy = Closure.DELEGATE_FIRST
  body
.delegate = config
  body
()

  pipeline
{
     
// the declarative pipeline as-is as it was previously used in a Jenkinsfile in a repository
 
}
}

--
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/c878f51d-8097-43fb-a0f5-a95b471f0184%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO37hbi18NX6yiGCj8_7AApgY0UTt4Q7_eXJcH26%3DQx9NtWBug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can I load a declarative Jenkinsfile via a shared library?

Idan Adar
Any prerequisites?

On Wed, Jan 10, 2018 at 8:46 PM, Daniel Butler <[hidden email]> wrote:
I believe this was added a month or two ago.

On 10 Jan 2018 6:33 pm, "Idan Adar" <[hidden email]> wrote:
Is the following feasible?

1. Setup a Shared Library in the Jenkins settings
2. In every repository requiring the Jenkinsfile (it is the same one used in multiple repos...), use the following in the Jenkinsfile of the repository instead:


@Library("my-shared-library") _
    standardPipeline
{
       
// properties passed to the shared library
   
}

3. In the Shared Library, use this: 

def call(body) {
 
def config = [:]
  body
.resolveStrategy = Closure.DELEGATE_FIRST
  body
.delegate = config
  body
()

  pipeline
{
     
// the declarative pipeline as-is as it was previously used in a Jenkinsfile in a repository
 
}
}

--
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/c878f51d-8097-43fb-a0f5-a95b471f0184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/EG1BLWQq1Mo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO37hbi18NX6yiGCj8_7AApgY0UTt4Q7_eXJcH26%3DQx9NtWBug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Idan Adar

--
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/CAA6x3wf69HCQo%3DeYaE%3DR_41%2BCWSN3xQqPRokp8ETUeqkJwpdoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can I load a declarative Jenkinsfile via a shared library?

Idan Adar
Indeed possible. See blog post: https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/

--
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/21af1a76-b3e0-4411-bdd8-f3e996116ce3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can I load a declarative Jenkinsfile via a shared library?

Joe Cavanaugh
You have to have the declarative pipeline 1.2 or higher to do this. I am having issues putting the "powershell" keyword in the library... otherwise it seems to work. 

On Thursday, January 11, 2018 at 1:41:50 AM UTC-6, Idan Adar wrote:
Indeed possible. See blog post: <a href="https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fblog%2F2017%2F10%2F02%2Fpipeline-templates-with-shared-libraries%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH9RZqxzvWKSBvqd8e9hk4CNvyUtg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fblog%2F2017%2F10%2F02%2Fpipeline-templates-with-shared-libraries%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH9RZqxzvWKSBvqd8e9hk4CNvyUtg&#39;;return true;">https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/

--
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/8727eb84-c74c-4141-bf07-bedfdb9e764f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.