Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Build inputs from Jenkins to python

I am new to Jenkins and Python. I have jenkings test build Project with build parameters. Below is the screen shot for reference.

ScreenShot of build Parameters

I need to Pass this inputs to python script "test.py"

My execute command is looks like below:

    /usr/bin/python2.7 /scripts/test.py

test.py script:

  import time
  import os
  input1 = os.getenv("input1")
  input2 = os.getenv("input2")
  Dropdown = os.getenv("Dropdown1")
  Dropdown2 = os.getenv("Dropdown2")
  print input1
  print input2
  print Dropdown
  print Dropdown2

Console output:

Building in workspace /root/.jenkins/workspace/Inputs-Test
[Inputs-Test] $ /bin/sh -xe /tools/apache-tomcat-8.5.24/temp/jenkins3261310337115825812.sh
+ /usr/bin/python2.7 /project/test.py
None
None
None
None
Finished: SUCCESS
like image 534
meteor23 Avatar asked Dec 24 '22 11:12

meteor23


1 Answers

Since those parameters are part of the environment of the Jenkins created process you are always able to access them in the following way.

import os
input1 = os.getenv("Input1")
input2 = os.getenv("input2")
Dropdown = os.getenv("Dropdown")
Dropdown2 = os.getenv("dropdown2")

Now set those in your setupClass or your test setup method.

like image 78
Ilhicas Avatar answered Dec 28 '22 06:12

Ilhicas