-
Task
-
Resolution: Unresolved
-
Major
-
Jenkins version 2.64
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.
[JENKINS-53903] 'unable to resolve class hudson.util.Secret' exception in groovy script in ANT build.xml
Labels | New: ant groovy jenkins |
Description |
Original:
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. |
New:
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. |
Priority | Original: Minor [ 4 ] | New: Major [ 3 ] |
Assignee | Original: Armando Fernandez [ armfergom ] | New: Jayakumari A [ jayram ] |
Assignee | Original: Jayakumari A [ jayram ] | New: Armando Fernandez [ armfergom ] |
Assignee | Original: Armando Fernandez [ armfergom ] | New: SCM/JIRA link daemon [ scm_issue_link ] |
Assignee | Original: SCM/JIRA link daemon [ scm_issue_link ] | New: Armando Fernandez [ armfergom ] |