Capture/Store output of shell or python or groovy script

51 views
Skip to first unread message

Dashmeet Anand

unread,
Apr 10, 2024, 7:25:11 PM4/10/24
to jenkins-job-builder
Hi,
I've been going through the documentation for too long. I've not been able to find a way where one could run python or shell script and assign the output to a variable. 
The variable should then be available to use in the job or pipeline config.

Is there a way to do so? If yes, I would appreciate the link to the doc.

Thanks,
Dashmeet

Vsevolod Fedorov

unread,
Apr 11, 2024, 9:23:54 AM4/11/24
to Dashmeet Anand, jenkins-job-builder

Hi,

Usual way to do this it like that:

------------>8 ---------------------------

- builders:
  - shell: |
      #!/bin/bash -xe
      echo "Here we somehow populate my_var_1 and my_var_2 variables:"
      my_var_1="My value 1"
      my_var_2="My value 2"
      # Note: No double quotes around values here
      # because MY_VARS.envvar is not a bash file,
      # but a Java properties file.
      echo -n > MY_VARS.envvar
      echo "MY_VAR_1=$my_var_1" >> MY_VARS.envvar
      echo "MY_VAR_2=$my_var_2" >> MY_VARS.envvar

  - inject:
      properties-file: MY_VARS.envvar'

  # Now, we have MY_VAR_1 and MY_VAR_2 in the environment:
  - shell: |
      #!/bin/bash -xe
      echo "MY_VAR_1=$MY_VAR_1"
      echo "MY_VAR_2=$MY_VAR_2"

publishers:
  # Store .envvar files - very useful for job debugging.
  - archive:
      artifacts: '*.envvar'
      allow-empty: 'true'

------------ 8<---------------------------


Vsevolod.

--
You received this message because you are subscribed to the Google Groups "jenkins-job-builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins-job-bui...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkins-job-builder/e667f7f6-78cd-494f-b643-2f0f24214f7fn%40googlegroups.com.

Dashmeet Anand

unread,
Apr 11, 2024, 4:50:16 PM4/11/24
to jenkins-job-builder
Thank you! 
It works. 
Reply all
Reply to author
Forward
0 new messages