[JIRA] (JENKINS-38110) Library section within declarative syntax to explicitly load shared libraries

2 views
Skip to first unread message

pwolf@cloudbees.com (JIRA)

unread,
Sep 9, 2016, 1:23:01 PM9/9/16
to jenkinsc...@googlegroups.com
Patrick Wolf created an issue
 
Jenkins / New Feature JENKINS-38110
Library section within declarative syntax to explicitly load shared libraries
Issue Type: New Feature New Feature
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2016/Sep/09 5:22 PM
Priority: Minor Minor
Reporter: Patrick Wolf

Right now users must use an @Library annotation to load libraries in Pipeline script. This works within a Pipeline with declarative syntax but must be called outside of the pipeline block.

It would be nice if we could load libraries within the pipeline block with a library configuration section.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

p.leibiger@codecraft.de (JIRA)

unread,
Oct 15, 2016, 7:03:05 AM10/15/16
to jenkinsc...@googlegroups.com
Peter Leibiger commented on New Feature JENKINS-38110
 
Re: Library section within declarative syntax to explicitly load shared libraries

Not sure if this is the right issue but there are probably some things to consider for this issue.
Up until version 0.4 I was able to use @Library like this:

@Library('foo@master')
def util = new foo.Util()

timestamps {
  pipeline {
    agent docker: 'maven:3-jdk-8'

    stages {
      stage('Pre-Build') {
        util.doSomething()
      }
      // more stages
    }

    notifications {
      success {
        util.notifyBuildStatusSuccess()
      }
      ...
    }
}

Now with 0.4 it fails to find the @Library annotation, I can work around by using the FQN.
But I can't get a single Util instance to work anymore, best I came up with is this:

@Library('foo@master')
import foo.Util

// timestamps don't work anymore
//timestamps {
  pipeline {
    agent docker: 'maven:3-jdk-8'

    stages {
      stage('Pre-Build') {
        script {
          def util = new Util()
          util.doSomething()
        }
      }
      // more stages
    }

    notifications {
      success {
        script {
          def util = new Util()
          util.notifyBuildStatusSuccess()
        }
      }
      ...
    }
  }
//}

I tried putting the Util in environment but that throws ....sandbox.RejectedAccessException:

@Library('foo@master')
import foo.Util

// timestamps don't work anymore
//timestamps {
  pipeline {
    agent docker: 'maven:3-jdk-8'

    environment {
      util = new Util()
    }

    stages {
      stage('Pre-Build') {
        script {
          env.util.doSomething()
        }
      }
      // more stages
    }

    notifications {
      success {
        script {
          env.util.notifyBuildStatusSuccess()
        }
      }
      ...
    }
  }
//}

p.leibiger@codecraft.de (JIRA)

unread,
Oct 15, 2016, 7:04:01 AM10/15/16
to jenkinsc...@googlegroups.com
Peter Leibiger edited a comment on New Feature JENKINS-38110
Not sure if this is the right issue but there are probably some things to consider for this issue.
Up until version 0.4 I was able to use {{@Library}} like this:

{code}

@Library('foo@master')
def util = new foo.Util()

timestamps {
  pipeline {
    agent docker: 'maven:3-jdk-8'

    stages {
      stage('Pre-Build') {
        util.doSomething()
      }
      // more stages
    }

    notifications {
      success {
        util.notifyBuildStatusSuccess()
      }
      ...
    }
}
{code}


Now with 0.4 it fails to find the {{@Library}} annotation, I can work around by using the FQN.
But I can't get a single {{Util}} instance to work anymore, best I came up with is this:

{code}
@
org.jenkinsci.plugins.workflow.libs. Library('foo@master')

import foo.Util

// timestamps don't work anymore
//timestamps {
  pipeline {
    agent docker: 'maven:3-jdk-8'

    stages {
      stage('Pre-Build') {
        script {
          def util = new Util()
          util.doSomething()
        }
      }
      // more stages
    }

    notifications {
      success {
        script {
          def util = new Util()
          util.notifyBuildStatusSuccess()
        }
      }
      ...
    }
  }
//}
{code}


I tried putting the {{Util}} in {{environment}} but that throws {{....sandbox.RejectedAccessException}}:

{code}
@
org.jenkinsci.plugins.workflow.libs. Library('foo@master')

import foo.Util

// timestamps don't work anymore
//timestamps {
  pipeline {
    agent docker: 'maven:3-jdk-8'

    environment {
      util = new Util()
    }

    stages {
      stage('Pre-Build') {
        script {
          env.util.doSomething()
        }
      }
      // more stages
    }

    notifications {
      success {
        script {
          env.util.notifyBuildStatusSuccess()
        }
      }
      ...
    }
  }
//}
{code}

p.leibiger@codecraft.de (JIRA)

unread,
Oct 15, 2016, 7:31:03 AM10/15/16
to jenkinsc...@googlegroups.com

Actually this works as well. Until 0.4 it worked without the import, now it doesn't.

@org.jenkinsci.plugins.workflow.libs.Library('foo@master')
import foo.Util

// doesn't work anymore
// def util = new foo.Util()
def util = new Util()

domi@fortysix.ch (JIRA)

unread,
Dec 23, 2016, 3:40:02 AM12/23/16
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 28, 2017, 6:17:04 PM2/28/17
to jenkinsc...@googlegroups.com
Andrew Bayer started work on New Feature JENKINS-38110
 
Change By: Andrew Bayer
Status: Open In Progress

andrew.bayer@gmail.com (JIRA)

unread,
Feb 28, 2017, 7:57:04 PM2/28/17
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Mar 2, 2017, 11:27:01 AM3/2/17
to jenkinsc...@googlegroups.com

scm_issue_link@java.net (JIRA)

unread,
Mar 3, 2017, 7:55:05 PM3/3/17
to jenkinsc...@googlegroups.com
SCM/JIRA link daemon commented on New Feature JENKINS-38110
 
Re: Library section within declarative syntax to explicitly load shared libraries

Code changed in jenkins
User: Andrew Bayer
Path:
pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTLibraries.java
pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTPipelineDef.java
pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidator.java
pipeline-model-api/src/main/resources/ast-schema.json
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Libraries.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Root.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ClosureModelTranslator.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/LibrariesTranslator.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
http://jenkins-ci.org/commit/pipeline-model-definition-plugin/91d361bb30134b79fdf6ed4089e7cd110008c289
Log:
JENKINS-38110 Add a libraries section

Note that this is very preliminary at this point - like, it doesn't
actually call the library step yet, since we don't yet have a release
of workflow-cps-global-lib-plugin with that included to depend on. We
also don't have parsing tests or any of that jazz. But that's ok.

scm_issue_link@java.net (JIRA)

unread,
Mar 3, 2017, 7:55:06 PM3/3/17
to jenkinsc...@googlegroups.com

Code changed in jenkins
User: Andrew Bayer
Path:
pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTLibraries.java
pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTPipelineDef.java
pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidator.java
pipeline-model-api/src/main/resources/ast-schema.json

pipeline-model-definition/pom.xml


pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Libraries.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Root.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ClosureModelTranslator.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/LibrariesTranslator.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy

pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java
pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
pipeline-model-definition/src/test/resources/errors/emptyLibrariesDirective.groovy
pipeline-model-definition/src/test/resources/errors/invalidLibrariesDirectiveContent.groovy
pipeline-model-definition/src/test/resources/librariesDirective.groovy
pom.xml
http://jenkins-ci.org/commit/pipeline-model-definition-plugin/0c7d4fdadd4ad3b2a749853a3bb3eee567c54ae6
Log:
Merge pull request #128 from abayer/jenkins-38110

JENKINS-38110 Add a libraries section

andrew.bayer@gmail.com (JIRA)

unread,
Mar 3, 2017, 7:56:01 PM3/3/17
to jenkinsc...@googlegroups.com

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:26:02 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Fixed
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages