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

'unable to resolve class hudson.util.Secret' exception in groovy script in ANT build.xml

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I am using Jenkins and ANT build to automate our build and release process.
      I am using 'hudson.util.Secret' API to encrypt and decrypt passwords in Jenkins.
      I have encrypted all passwords and kept in a property file using the API. Now, during the build process, I need to decrypt the password dynamically.
      For that, I decided to use groovy script for decryption process (please refer the below code) in ant build.xml file.

      Code

      import hudson.util.Secret
      // To decrypt Old Password
      def password = Secret.fromString("{AQAAABAAAAAQAoxLF+PLmbaD1FJiLZznGOZ4pEJI4hnXHRjXVkLBrFM=}")
      def decPassword = password.getPlainText()
      println("Decrypted Password = "+decPassword)

      The above code is working fine in Jenkins 'Script Console'. But while using the same in ANT build.xml file as groovy script, 'unable to resolve class hudson.util.Secret' exception is thrown .

      Code in Ant build.xml

      <?xml version="1.0" encoding="windows-1252" ?>
      <project xmlns="antlib:org.apache.tools.ant" name="Sample Build XML" default="main" basedir=".">
      <target name="main">
      <script language="groovy" classpath = "C:/jenkins/war/WEB-INF/lib/groovy-all-2.4.11.jar">
      import hudson.util.Secret
      // To decrypt Old Password
      def password = Secret.fromString("{AQAAABAAAAAQAoxLF+PLmbaD1FJiLZznGOZ4pEJI4hnXHRjXVkLBrFM=}")
      def decPassword = password.getPlainText()
      println("Decrypted Password = "+decPassword)
      </script>
      </target>
      </project>

      Exception

      BUILD FAILED
      C:\tools\my_samples\sample_build.xml:4: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Script1.groovy: 2: unable to resolve class hudson.util.Secret
      @ line 2, column 2.
      import hudson.util.Secret
      ^

      1 error

      How to resolve 'unable to resolve class hudson.util.Secret' exception in groovy script in ANT build.xml?

      Any other code change is needed in buid.xml file?

      Thanks in advance.

       

        Attachments

          Activity

          jayram Jayakumari A created issue -
          jayram Jayakumari A made changes -
          Field Original Value New Value
          Labels ant groovy jenkins
          jayram Jayakumari A made changes -
          Description I am using Jenkins and ANT build to automate our build and release process.
          I am using **'hudson.util.Secret' API** to encrypt and decrypt passwords in Jenkins.
          I have encrypted all passwords and kept in a property file using the API. Now, during the build process, I need to decrypt the password dynamically.
          For that, I decided to use groovy script for decryption process (please refer the below code) in ant build.xml file.

          +*Code*+

          _import hudson.util.Secret_
           _// To decrypt Old Password_
           _def password = Secret.fromString("\{AQAAABAAAAAQAoxLF+PLmbaD1FJiLZznGOZ4pEJI4hnXHRjXVkLBrFM=}")_
           _def decPassword = password.getPlainText()_
           _println("Decrypted Password = "+decPassword)_

          The above code is working fine in Jenkins 'Script Console'. But while using the same in ANT build.xml file as groovy script, 'unable to resolve class hudson.util.Secret' exception is thrown .

          +*Code in Ant build.xml*+

          _<?xml version="1.0" encoding="windows-1252" ?>_
           _<project xmlns="antlib:org.apache.tools.ant" name="Sample Build XML" default="main" basedir=".">_
           _<target name="main">_
           _<script language="groovy" classpath = "C:/jenkins/war/WEB-INF/lib/groovy-all-2.4.11.jar">_
           _import hudson.util.Secret_
           _// To decrypt Old Password_
           _def password = Secret.fromString("\{AQAAABAAAAAQAoxLF+PLmbaD1FJiLZznGOZ4pEJI4hnXHRjXVkLBrFM=}")_
           _def decPassword = password.getPlainText()_
           _println("Decrypted Password = "+decPassword)_
           _</script>_
           _</target>_
           _</project>_

          +*Exception*+

          _BUILD FAILED_
           _C:\tools\my_samples\sample_build.xml:4: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:_
           _Script1.groovy: 2: unable to resolve class hudson.util.Secret_
           _@ line 2, column 2._
           _import hudson.util.Secret_
           _^_
           
           _1 error_

          **How to resolve 'unable to resolve class hudson.util.Secret' exception in groovy script in ANT build.xml?**

          Any other code change is needed in buid.xml file?

          Thanks in advance.

           
          I am using Jenkins and ANT build to automate our build and release process.
           I am using *'hudson.util.Secret' API* to encrypt and decrypt passwords in Jenkins.
           I have encrypted all passwords and kept in a property file using the API. Now, during the build process, I need to decrypt the password dynamically.
           For that, I decided to use groovy script for decryption process (please refer the below code) in ant build.xml file.

          +*Code*+

          _import hudson.util.Secret_
           _// To decrypt Old Password_
           _def password = Secret.fromString("\{AQAAABAAAAAQAoxLF+PLmbaD1FJiLZznGOZ4pEJI4hnXHRjXVkLBrFM=}")_
           _def decPassword = password.getPlainText()_
           _println("Decrypted Password = "+decPassword)_

          The above code is working fine in Jenkins 'Script Console'. But while using the same in ANT build.xml file as groovy script, 'unable to resolve class hudson.util.Secret' exception is thrown .

          +*Code in Ant build.xml*+

          _<?xml version="1.0" encoding="windows-1252" ?>_
           _<project xmlns="antlib:org.apache.tools.ant" name="Sample Build XML" default="main" basedir=".">_
           _<target name="main">_
           _<script language="groovy" classpath = "C:/jenkins/war/WEB-INF/lib/groovy-all-2.4.11.jar">_
           _import hudson.util.Secret_
           _// To decrypt Old Password_
           _def password = Secret.fromString("\{AQAAABAAAAAQAoxLF+PLmbaD1FJiLZznGOZ4pEJI4hnXHRjXVkLBrFM=}")_
           _def decPassword = password.getPlainText()_
           _println("Decrypted Password = "+decPassword)_
           _</script>_
           _</target>_
           _</project>_

          +*Exception*+

          _BUILD FAILED_
           _C:\tools\my_samples\sample_build.xml:4: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:_
           _Script1.groovy: 2: unable to resolve class hudson.util.Secret_
           _@ line 2, column 2._
           _import hudson.util.Secret_
           _^_

          _1 error_

          *How to resolve 'unable to resolve class hudson.util.Secret' exception in groovy script in ANT build.xml?*

          Any other code change is needed in buid.xml file?

          Thanks in advance.

           
          jayram Jayakumari A made changes -
          Priority Minor [ 4 ] Major [ 3 ]
          jayram Jayakumari A made changes -
          Assignee Armando Fernandez [ armfergom ] Jayakumari A [ jayram ]
          jayram Jayakumari A made changes -
          Assignee Jayakumari A [ jayram ] Armando Fernandez [ armfergom ]
          jayram Jayakumari A made changes -
          Assignee Armando Fernandez [ armfergom ] SCM/JIRA link daemon [ scm_issue_link ]
          jayram Jayakumari A made changes -
          Assignee SCM/JIRA link daemon [ scm_issue_link ] Armando Fernandez [ armfergom ]

            People

            Assignee:
            armfergom Armando Fernandez
            Reporter:
            jayram Jayakumari A
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: