0

I am trying to run a python script on Jenkins

import csv
import time
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
search_term = input("Enter the search (Two Words at most) :")

Is there a way to get this input in Jenkins?

1 Answer 1

1

If I'm understanding you correctly you would like your Jenkins pipeline to request input and then passing that input to your python code. I guess then you should remove search_term = input() from your python code and set this as an argument with something like:

parser = argparse.ArgumentParser(description="somedescriptionhere")
parser.add_argument('-s', '--search_term', help="sometexthere", type=str)
args = parser.parse_args()
search_term = args.search_germ

then you can put the following on a step on a jenkins pipeline stage:

input (id: 'userInput', message: 'Enter the search (Two Words at most) :', parameters: [
    [$class: 'TextParameterDefinition',
    defaultValue: '',
    description: 'Some suitable text for your needs',
    name: 'search_term']
])
sh(script: "timeout --signal=KILL 600 python3 yourpythoncode.py -s ${search_term}")

That should ask for input on execution and then pass the value to this python execution.

Sign up to request clarification or add additional context in comments.

3 Comments

what is parser?
I use normally use the argparse parser declaration like in " parser = argparse.ArgumentParser(description="somedescription")" and then add arguments and return them with "args = parser.parse_args()" like described here: docs.python.org/3/library/argparse.html
I've updated my answer reflecting how the argument parsing for the python part as an example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.