Answers: <p>You have not instantiated the Utils class in the myorg classpath so you cannot reference the method <code>echoTest()</code>. Try <code>Utils.echoTest</code> or just <code>echoTest()</code></p>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-23T23:41:03.267Z
Answers: 2019-04-23T23:41:03.267Z
Answers: casey vega
Answers: <p>When you see <code>scriptsecurity.sandbox</code> error, that means you need to allow the script from Jenkins script approval page https:///scriptApproval/
  Also I would recommend you not to import your package directly within your pipeline. Instead I would define a step under <code>./vars</code> folder and only there import the custom package</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-23T23:14:00.590Z
Answers: Shared libraries are considered trusted and would not throw a sandbox error. See https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries for more details.
Answers: casey vega
Answers: CC BY-SA 4.0
Answers: 2019-04-23T20:48:35.980Z
Answers: 2019-04-23T20:48:35.980Z
Answers: fredericrous
Body: <p>Recently I tried to add Shared Libraries to my Jenkins instance to make it easier to maintain all code that runs in each project.</p>
  
  <ol>
  <li>I have a repo <code>myorg/jenkins</code></li>
  </ol>
  
  <p>Inside of it I have Jenkinsfile and groovy file meant to contain libraries, Jenkinsfile looks like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Library('utils@develop')_
  import com.*
  
  jenkinsSlave = "slave.myorg.com"
  
  node(jenkinsSlave) {
      stage('Test') {
          def var = "kek"
          myorg.echoTest(var)
      }
  }
  </code></pre>
  
  <p>I try to execute <code>echoTest</code> method there and I'm passing one argument.</p>
  
  <p>Shared libs look like this (Jenkinsfile is in root directory of this repo):</p>
  
  <pre><code>src
  └── com
      └── myorg
          └── Utils.groovy
  </code></pre>
  
  <p>Utils.groovy:</p>
  
  <pre class="lang-java prettyprint-override"><code>#!/usr/bin/groovy
  package com.myorg
  
  
  def echoTest(test) {
    println("Test + ${test}")
  }
  
  return this
  </code></pre>
  
  <p>In Jenkins I've added this repo to global libraries section and I pointed to main branch, which is develop in this case. </p>
  
  <p>Unfortuantely, when I run build jenkins throws this:</p>
  
  <pre><code>groovy.lang.MissingPropertyException: No such property: myorg for class: groovy.lang.Binding
      at groovy.lang.Binding.getVariable(Binding.java:63)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:264)
      at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
      at org.kohsuke.groovy.sandbox.impl.Checker.checke
  
  [...]
  </code></pre>
  
  <p>I tried various configuration but so far I cannot make this work. I've tried to follow few tutorials about implementing this and I cannot pass through here. </p>
  
  <p>Does someone notice any misconfiguration in this setup?</p>
  
Tags: <jenkins><continuous-integration><jenkins-pipeline><jenkinsfile>
Title: Jenkins Shared lib not working properly
UserDisplayName: vaporwave_sailor
ThreadText: # Jenkins Shared lib not working properly
  
  (Asked by: username_0 on 2019-04-07)
  
  Recently I tried to add Shared Libraries to my Jenkins instance to make it easier to maintain all code that runs in each project.
  
  1. I have a repo `myorg/jenkins`
  
  Inside of it I have Jenkinsfile and groovy file meant to contain libraries, Jenkinsfile looks like this:
  
  ```java
  @Library('utils@develop')_
  import com.*
  
  jenkinsSlave = "slave.myorg.com"
  
  node(jenkinsSlave) {
      stage('Test') {
          def var = "kek"
          myorg.echoTest(var)
      }
  }
  
  ```
  
  I try to execute `echoTest` method there and I'm passing one argument.
  
  Shared libs look like this (Jenkinsfile is in root directory of this repo):
  
  ```
  src
  └── com
      └── myorg
          └── Utils.groovy
  
  ```
  
  Utils.groovy:
  
  ```java
  #!/usr/bin/groovy
  package com.myorg
  
  def echoTest(test) {
    println("Test + ${test}")
  }
  
  return this
  
  ```
  
  In Jenkins I've added this repo to global libraries section and I pointed to main branch, which is develop in this case.
  
  Unfortuantely, when I run build jenkins throws this:
  
  ```
  groovy.lang.MissingPropertyException: No such property: myorg for class: groovy.lang.Binding
      at groovy.lang.Binding.getVariable(Binding.java:63)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:264)
      at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
      at org.kohsuke.groovy.sandbox.impl.Checker.checke
  
  [...]
  
  ```
  
  I tried various configuration but so far I cannot make this work. I've tried to follow few tutorials about implementing this and I cannot pass through here.
  
  Does someone notice any misconfiguration in this setup?
  
  **Tags:** jenkins, continuous-integration, jenkins-pipeline, jenkinsfile
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-04-23. Score: 1
  
  You have not instantiated the Utils class in the myorg classpath so you cannot reference the method `echoTest()`. Try `Utils.echoTest` or just `echoTest()`
  
  
  ---
  
  ### Answer by username_2 on 2019-04-23. Score: 0
  
  When you see `scriptsecurity.sandbox` error, that means you need to allow the script from Jenkins script approval page https:///scriptApproval/
  Also I would recommend you not to import your package directly within your pipeline. Instead I would define a step under `./vars` folder and only there import the custom package
  
  > **Comments:**
  > **username_1**: Shared libraries are considered trusted and would not throw a sandbox error. See https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries for more details.  
  
  ---
  
  