Groovy base64 encode/decode input string

Veeresh Kumar
2 min readOct 2, 2021

--

In this article, we will see how to encrypt and decrypt base64 data in using groovy in jenkins.

I have below two functions:

base64Encode():

This function takes the inputString (any text string) and returns the encoded string.

base64Decode():

This function takes base64 encodedString input and returns decoded string.

Below is the script:

In the above example:

  • Define text String variable:

text = “Hello Engineers!!, This text will be Base64 encoded and decoded”

  • Call base64Encode() function by passing text variable as input and stores output in encoded variable:

encoded = base64Encode(text)

  • Call base64Decode() function by passing encoded variables as input and stores output in decoded variable:

decoded = base64Decode(encoded)

  • Lastly, printing all variables values into output.

To run the above script create Jenkins pipeline job:

  • Login to Jenkins Server.
  • In Dashboard, Click on New Item of left pane.
  • Provide the Job/Item name and Select Pipeline, Click OK.

Ex; base64EncodeDecode

  • Select Pipeline Menu, Copy &Paste the above script and Save.
  • From the create pipeline, Click on Build Now.
  • Once the job is successful, you can click on the latest Build_Number and Click on Console Output to see the results.

Note: During first run you might face Security Approval issues due to static methods called in the pipeline script. In order to make job successful, Kindly, Approve Script in In_Script Approval pending scripts.

Thank you …!! Hope this helps !!

--

--

Veeresh Kumar

He is a Sr. DevOps Engineer loves to automate cloud infrastructure and App deployments. #Terraform #Azure #Jenkins #Ansible #Chef #Bash #PowerShell #AWS #GCP