Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48527

"Accessing steps" example in Extending with Shared Libraries fails

    Details

    • Similar Issues:

      Description

      In trying the examples from the "extending with Shared Libraries" documentation found here:

      https://jenkins.io/doc/book/pipeline/shared-libraries/

      other examples work without issues, but the first example under "Accessing steps" suggests using a method outside of an enclosing class:

      // src/org/foo/Zot.groovy
      package org.foo;

      def checkOutFrom(repo) {
        git url: "git@github.com:jenkinsci/${repo}"
      }

      called like this:

      def z = new org.foo.Zot()
      z.checkOutFrom(repo)

       

      When I try this, it fails to resolve the class:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      WorkflowScript: 9: unable to resolve class org.foo.Zot
      @ line 9, column 17.
      def z = new org.foo.Zot()
      ^

      1 error

      at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958)
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554)
      at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
      at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:129)
      at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:123)
      at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:517)
      at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:480)
      at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:268)
      at hudson.model.ResourceController.execute(ResourceController.java:97)
      at hudson.model.Executor.run(Executor.java:421)
      Finished: FAILURE

       

      The error isn't all that surprising, since this really isn't a class.  It looks like perhaps there's something missing from the example in the documentation.

        Attachments

          Activity

          Hide
          abayer Andrew Bayer added a comment -

          Do you have the @Library annotation for the shared library in your Jenkinsfile? You either need that or you need to have the shared library configured in Jenkins to load implicitly.

          Show
          abayer Andrew Bayer added a comment - Do you have the @Library annotation for the shared library in your Jenkinsfile? You either need that or you need to have the shared library configured in Jenkins to load implicitly.
          Hide
          euphxenos Andrew Lawrence added a comment -

          Yes.  I've tried both "library 'mytestlib'" and "@Library('mytestlib') _".  Both work for loading singletons out of vars/, but neither works for loading a function outside of a class definition like in the "Accessing steps" example.

          Show
          euphxenos Andrew Lawrence added a comment - Yes.  I've tried both "library 'mytestlib'" and "@Library('mytestlib') _".  Both work for loading singletons out of vars/, but neither works for loading a function outside of a class definition like in the "Accessing steps" example.
          Hide
          euphxenos Andrew Lawrence added a comment -

          I was missing "return this;" at the end of Zot.groovy.  I'd suggest adding this to the example.

          Show
          euphxenos Andrew Lawrence added a comment - I was missing "return this;" at the end of Zot.groovy.  I'd suggest adding this to the example.
          Show
          slide_o_mix Alex Earl added a comment - See https://github.com/jenkins-infra/jenkins.io/pull/1289
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Alex Earl
          Path:
          content/doc/book/pipeline/shared-libraries.adoc
          http://jenkins-ci.org/commit/jenkins.io/42d54246f2d47ae2acb5e506c4a536290ca6524e
          Log:
          Fix JENKINS-48527

          There is a missing return this in the example for Zot.groovy. Without this, the issue in the issue arises. This clarifies the example to make sure the user knows that `return this` is needed

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Alex Earl Path: content/doc/book/pipeline/shared-libraries.adoc http://jenkins-ci.org/commit/jenkins.io/42d54246f2d47ae2acb5e506c4a536290ca6524e Log: Fix JENKINS-48527 There is a missing return this in the example for Zot.groovy. Without this, the issue in the issue arises. This clarifies the example to make sure the user knows that `return this` is needed
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Liam Newman
          Path:
          content/doc/book/pipeline/shared-libraries.adoc
          http://jenkins-ci.org/commit/jenkins.io/3367043eab603339c93a24d11f4a9eac6badc879
          Log:
          Merge pull request #1289 from slide/patch-1

          Fix JENKINS-48527

          Compare: https://github.com/jenkins-infra/jenkins.io/compare/d4b016317428...3367043eab60

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Liam Newman Path: content/doc/book/pipeline/shared-libraries.adoc http://jenkins-ci.org/commit/jenkins.io/3367043eab603339c93a24d11f4a9eac6badc879 Log: Merge pull request #1289 from slide/patch-1 Fix JENKINS-48527 Compare: https://github.com/jenkins-infra/jenkins.io/compare/d4b016317428...3367043eab60

            People

            • Assignee:
              Unassigned
              Reporter:
              euphxenos Andrew Lawrence
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: