Jenkins variable in groovy script





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'd like to use "$WORSKPACE" variable into a groovy file called by jenkins script. But all solutions found on SO failed :



// KO : Wks = build.getEnvironment(listener).get('WORKSPACE')
// KO : Wks = "${WORKSPACE}"
/* KO :
def thr = Thread.currentThread()
def build = thr?.executable
def envVarsMap = build.parent.builds[0].properties.get("WORKSPACE")
*/

// KO : def build = this.getProperty('binding').getVariable('build')
// KO : Wks = "%WORKSPACE%"


Message I got :
Scripts not permitted to use method groovy.lang.GroovyObject setProperty java.lang.String java.lang.Object (JenkinsHelper.name). Administrators can decide whether to approve or reject this signature.



Any idea of code or option to set to allow Jenkins script to work ?



My sample case :



File JenkinsHelper.groovy :



    class JenkinsHelper {
def init(String sln) {
Wks = "%WORKSPACE%"
}
}
return new JenkinsHelper();


Call from jenkins script :



def helper = load 'C:/.../test.groovy'
helper.init("Mon SLN")


Thanks :)










share|improve this question































    1















    I'd like to use "$WORSKPACE" variable into a groovy file called by jenkins script. But all solutions found on SO failed :



    // KO : Wks = build.getEnvironment(listener).get('WORKSPACE')
    // KO : Wks = "${WORKSPACE}"
    /* KO :
    def thr = Thread.currentThread()
    def build = thr?.executable
    def envVarsMap = build.parent.builds[0].properties.get("WORKSPACE")
    */

    // KO : def build = this.getProperty('binding').getVariable('build')
    // KO : Wks = "%WORKSPACE%"


    Message I got :
    Scripts not permitted to use method groovy.lang.GroovyObject setProperty java.lang.String java.lang.Object (JenkinsHelper.name). Administrators can decide whether to approve or reject this signature.



    Any idea of code or option to set to allow Jenkins script to work ?



    My sample case :



    File JenkinsHelper.groovy :



        class JenkinsHelper {
    def init(String sln) {
    Wks = "%WORKSPACE%"
    }
    }
    return new JenkinsHelper();


    Call from jenkins script :



    def helper = load 'C:/.../test.groovy'
    helper.init("Mon SLN")


    Thanks :)










    share|improve this question



























      1












      1








      1








      I'd like to use "$WORSKPACE" variable into a groovy file called by jenkins script. But all solutions found on SO failed :



      // KO : Wks = build.getEnvironment(listener).get('WORKSPACE')
      // KO : Wks = "${WORKSPACE}"
      /* KO :
      def thr = Thread.currentThread()
      def build = thr?.executable
      def envVarsMap = build.parent.builds[0].properties.get("WORKSPACE")
      */

      // KO : def build = this.getProperty('binding').getVariable('build')
      // KO : Wks = "%WORKSPACE%"


      Message I got :
      Scripts not permitted to use method groovy.lang.GroovyObject setProperty java.lang.String java.lang.Object (JenkinsHelper.name). Administrators can decide whether to approve or reject this signature.



      Any idea of code or option to set to allow Jenkins script to work ?



      My sample case :



      File JenkinsHelper.groovy :



          class JenkinsHelper {
      def init(String sln) {
      Wks = "%WORKSPACE%"
      }
      }
      return new JenkinsHelper();


      Call from jenkins script :



      def helper = load 'C:/.../test.groovy'
      helper.init("Mon SLN")


      Thanks :)










      share|improve this question
















      I'd like to use "$WORSKPACE" variable into a groovy file called by jenkins script. But all solutions found on SO failed :



      // KO : Wks = build.getEnvironment(listener).get('WORKSPACE')
      // KO : Wks = "${WORKSPACE}"
      /* KO :
      def thr = Thread.currentThread()
      def build = thr?.executable
      def envVarsMap = build.parent.builds[0].properties.get("WORKSPACE")
      */

      // KO : def build = this.getProperty('binding').getVariable('build')
      // KO : Wks = "%WORKSPACE%"


      Message I got :
      Scripts not permitted to use method groovy.lang.GroovyObject setProperty java.lang.String java.lang.Object (JenkinsHelper.name). Administrators can decide whether to approve or reject this signature.



      Any idea of code or option to set to allow Jenkins script to work ?



      My sample case :



      File JenkinsHelper.groovy :



          class JenkinsHelper {
      def init(String sln) {
      Wks = "%WORKSPACE%"
      }
      }
      return new JenkinsHelper();


      Call from jenkins script :



      def helper = load 'C:/.../test.groovy'
      helper.init("Mon SLN")


      Thanks :)







      variables jenkins groovy environment






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 15:30







      NitroDeath666x

















      asked Nov 22 '18 at 15:22









      NitroDeath666xNitroDeath666x

      185




      185
























          2 Answers
          2






          active

          oldest

          votes


















          1














          This is caused by Jenkins In-process Script Approval as a protection of possible execution of malicious scripts.



          If you're an admin, register your pipeline codes in Manage Jenkins > Configure System > Global Pipeline Libraries to avoid this scenario.



          References:





          1. https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries - Goes in details on writing a library.

          2. https://jenkins.io/doc/book/managing/script-approval






          share|improve this answer
























          • I guess you're right, this means most variables and functions are not allowed and script without admin rights have very poor capacities. I'm suprised. Shared libraries work fine, so I'll try to ask to admin to let me add my lib to be able to compile and test my program.

            – NitroDeath666x
            Nov 26 '18 at 10:16



















          1














          You should use groovy-style environenment variable format, not a Windows-style format:



          class JenkinsHelper {
          def init(String sln) {
          Wks = "${WORSKPACE}"
          }
          }





          share|improve this answer
























          • Doesn't it the same he tried in the sacond line of the example code?

            – handras
            Nov 22 '18 at 19:19











          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used

            – yorammi
            Nov 22 '18 at 19:40











          • Hi, thanks to both of you for your answers. Handras is right, I already tried your answer and it did fail for the same restriction reasons :o( : Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (JenkinsHelper.WORSKPACE). Administrators can decide whether to approve or reject this signature.

            – NitroDeath666x
            Nov 23 '18 at 10:54













          • If your an administrator you can approve it

            – yorammi
            Nov 23 '18 at 16:07












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434042%2fjenkins-variable-in-groovy-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          This is caused by Jenkins In-process Script Approval as a protection of possible execution of malicious scripts.



          If you're an admin, register your pipeline codes in Manage Jenkins > Configure System > Global Pipeline Libraries to avoid this scenario.



          References:





          1. https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries - Goes in details on writing a library.

          2. https://jenkins.io/doc/book/managing/script-approval






          share|improve this answer
























          • I guess you're right, this means most variables and functions are not allowed and script without admin rights have very poor capacities. I'm suprised. Shared libraries work fine, so I'll try to ask to admin to let me add my lib to be able to compile and test my program.

            – NitroDeath666x
            Nov 26 '18 at 10:16
















          1














          This is caused by Jenkins In-process Script Approval as a protection of possible execution of malicious scripts.



          If you're an admin, register your pipeline codes in Manage Jenkins > Configure System > Global Pipeline Libraries to avoid this scenario.



          References:





          1. https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries - Goes in details on writing a library.

          2. https://jenkins.io/doc/book/managing/script-approval






          share|improve this answer
























          • I guess you're right, this means most variables and functions are not allowed and script without admin rights have very poor capacities. I'm suprised. Shared libraries work fine, so I'll try to ask to admin to let me add my lib to be able to compile and test my program.

            – NitroDeath666x
            Nov 26 '18 at 10:16














          1












          1








          1







          This is caused by Jenkins In-process Script Approval as a protection of possible execution of malicious scripts.



          If you're an admin, register your pipeline codes in Manage Jenkins > Configure System > Global Pipeline Libraries to avoid this scenario.



          References:





          1. https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries - Goes in details on writing a library.

          2. https://jenkins.io/doc/book/managing/script-approval






          share|improve this answer













          This is caused by Jenkins In-process Script Approval as a protection of possible execution of malicious scripts.



          If you're an admin, register your pipeline codes in Manage Jenkins > Configure System > Global Pipeline Libraries to avoid this scenario.



          References:





          1. https://jenkins.io/doc/book/pipeline/shared-libraries/#global-shared-libraries - Goes in details on writing a library.

          2. https://jenkins.io/doc/book/managing/script-approval







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 12:53









          Quirino GervacioQuirino Gervacio

          91679




          91679













          • I guess you're right, this means most variables and functions are not allowed and script without admin rights have very poor capacities. I'm suprised. Shared libraries work fine, so I'll try to ask to admin to let me add my lib to be able to compile and test my program.

            – NitroDeath666x
            Nov 26 '18 at 10:16



















          • I guess you're right, this means most variables and functions are not allowed and script without admin rights have very poor capacities. I'm suprised. Shared libraries work fine, so I'll try to ask to admin to let me add my lib to be able to compile and test my program.

            – NitroDeath666x
            Nov 26 '18 at 10:16

















          I guess you're right, this means most variables and functions are not allowed and script without admin rights have very poor capacities. I'm suprised. Shared libraries work fine, so I'll try to ask to admin to let me add my lib to be able to compile and test my program.

          – NitroDeath666x
          Nov 26 '18 at 10:16





          I guess you're right, this means most variables and functions are not allowed and script without admin rights have very poor capacities. I'm suprised. Shared libraries work fine, so I'll try to ask to admin to let me add my lib to be able to compile and test my program.

          – NitroDeath666x
          Nov 26 '18 at 10:16













          1














          You should use groovy-style environenment variable format, not a Windows-style format:



          class JenkinsHelper {
          def init(String sln) {
          Wks = "${WORSKPACE}"
          }
          }





          share|improve this answer
























          • Doesn't it the same he tried in the sacond line of the example code?

            – handras
            Nov 22 '18 at 19:19











          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used

            – yorammi
            Nov 22 '18 at 19:40











          • Hi, thanks to both of you for your answers. Handras is right, I already tried your answer and it did fail for the same restriction reasons :o( : Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (JenkinsHelper.WORSKPACE). Administrators can decide whether to approve or reject this signature.

            – NitroDeath666x
            Nov 23 '18 at 10:54













          • If your an administrator you can approve it

            – yorammi
            Nov 23 '18 at 16:07
















          1














          You should use groovy-style environenment variable format, not a Windows-style format:



          class JenkinsHelper {
          def init(String sln) {
          Wks = "${WORSKPACE}"
          }
          }





          share|improve this answer
























          • Doesn't it the same he tried in the sacond line of the example code?

            – handras
            Nov 22 '18 at 19:19











          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used

            – yorammi
            Nov 22 '18 at 19:40











          • Hi, thanks to both of you for your answers. Handras is right, I already tried your answer and it did fail for the same restriction reasons :o( : Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (JenkinsHelper.WORSKPACE). Administrators can decide whether to approve or reject this signature.

            – NitroDeath666x
            Nov 23 '18 at 10:54













          • If your an administrator you can approve it

            – yorammi
            Nov 23 '18 at 16:07














          1












          1








          1







          You should use groovy-style environenment variable format, not a Windows-style format:



          class JenkinsHelper {
          def init(String sln) {
          Wks = "${WORSKPACE}"
          }
          }





          share|improve this answer













          You should use groovy-style environenment variable format, not a Windows-style format:



          class JenkinsHelper {
          def init(String sln) {
          Wks = "${WORSKPACE}"
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 18:50









          yorammiyorammi

          3,3651625




          3,3651625













          • Doesn't it the same he tried in the sacond line of the example code?

            – handras
            Nov 22 '18 at 19:19











          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used

            – yorammi
            Nov 22 '18 at 19:40











          • Hi, thanks to both of you for your answers. Handras is right, I already tried your answer and it did fail for the same restriction reasons :o( : Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (JenkinsHelper.WORSKPACE). Administrators can decide whether to approve or reject this signature.

            – NitroDeath666x
            Nov 23 '18 at 10:54













          • If your an administrator you can approve it

            – yorammi
            Nov 23 '18 at 16:07



















          • Doesn't it the same he tried in the sacond line of the example code?

            – handras
            Nov 22 '18 at 19:19











          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used

            – yorammi
            Nov 22 '18 at 19:40











          • Hi, thanks to both of you for your answers. Handras is right, I already tried your answer and it did fail for the same restriction reasons :o( : Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (JenkinsHelper.WORSKPACE). Administrators can decide whether to approve or reject this signature.

            – NitroDeath666x
            Nov 23 '18 at 10:54













          • If your an administrator you can approve it

            – yorammi
            Nov 23 '18 at 16:07

















          Doesn't it the same he tried in the sacond line of the example code?

          – handras
          Nov 22 '18 at 19:19





          Doesn't it the same he tried in the sacond line of the example code?

          – handras
          Nov 22 '18 at 19:19













          Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used

          – yorammi
          Nov 22 '18 at 19:40





          Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used

          – yorammi
          Nov 22 '18 at 19:40













          Hi, thanks to both of you for your answers. Handras is right, I already tried your answer and it did fail for the same restriction reasons :o( : Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (JenkinsHelper.WORSKPACE). Administrators can decide whether to approve or reject this signature.

          – NitroDeath666x
          Nov 23 '18 at 10:54







          Hi, thanks to both of you for your answers. Handras is right, I already tried your answer and it did fail for the same restriction reasons :o( : Scripts not permitted to use method groovy.lang.GroovyObject getProperty java.lang.String (JenkinsHelper.WORSKPACE). Administrators can decide whether to approve or reject this signature.

          – NitroDeath666x
          Nov 23 '18 at 10:54















          If your an administrator you can approve it

          – yorammi
          Nov 23 '18 at 16:07





          If your an administrator you can approve it

          – yorammi
          Nov 23 '18 at 16:07


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434042%2fjenkins-variable-in-groovy-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?