Jenkins variable in groovy script











up vote
1
down vote

favorite












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




























    up vote
    1
    down vote

    favorite












    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


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      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 at 15:30

























      asked Nov 22 at 15:22









      NitroDeath666x

      84




      84
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          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 at 10:16


















          up vote
          1
          down vote













          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 at 19:19










          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used
            – yorammi
            Nov 22 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 at 10:54












          • If your an administrator you can approve it
            – yorammi
            Nov 23 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',
          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








          up vote
          1
          down vote



          accepted










          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 at 10:16















          up vote
          1
          down vote



          accepted










          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 at 10:16













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          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 at 12:53









          Quirino Gervacio

          89679




          89679












          • 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 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 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 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 at 10:16












          up vote
          1
          down vote













          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 at 19:19










          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used
            – yorammi
            Nov 22 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 at 10:54












          • If your an administrator you can approve it
            – yorammi
            Nov 23 at 16:07















          up vote
          1
          down vote













          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 at 19:19










          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used
            – yorammi
            Nov 22 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 at 10:54












          • If your an administrator you can approve it
            – yorammi
            Nov 23 at 16:07













          up vote
          1
          down vote










          up vote
          1
          down vote









          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 at 18:50









          yorammi

          3,0811524




          3,0811524












          • Doesn't it the same he tried in the sacond line of the example code?
            – handras
            Nov 22 at 19:19










          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used
            – yorammi
            Nov 22 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 at 10:54












          • If your an administrator you can approve it
            – yorammi
            Nov 23 at 16:07


















          • Doesn't it the same he tried in the sacond line of the example code?
            – handras
            Nov 22 at 19:19










          • Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used
            – yorammi
            Nov 22 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 at 10:54












          • If your an administrator you can approve it
            – yorammi
            Nov 23 at 16:07
















          Doesn't it the same he tried in the sacond line of the example code?
          – handras
          Nov 22 at 19:19




          Doesn't it the same he tried in the sacond line of the example code?
          – handras
          Nov 22 at 19:19












          Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used
          – yorammi
          Nov 22 at 19:40




          Not in the JenkinsHelper.groovy file as he provided in the question, where %WORKSPACE% used
          – yorammi
          Nov 22 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 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 at 10:54














          If your an administrator you can approve it
          – yorammi
          Nov 23 at 16:07




          If your an administrator you can approve it
          – yorammi
          Nov 23 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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          How to ignore python UserWarning in pytest?

          Alexandru Averescu