I wrote this simple Jenkinsfile to execute a Python script.
The Jenkins job is supposed to take the value of the Jenkins build parameter and inject it to the python script, then execute the python script.
Here is the Jenkinsfile
pipeline{
agent any
parameters {
string description: 'write the week number', name: 'Week_Number'
}
stages{
stage("Pass Week Number&execute script"){
steps{
sh 'python3 statistics.py'
}
}
}
}
So what will happen is that I will go to Jenkins, choose build with parameters, and write some value in the Week_Number variable.
What i need to do is: Pass this Week_Number value as an integer to a variable in the python script.
This is the part of the Python script that I'm interested in:
weekNum = int(os.environ.get("Week_Number"))
I read online about the use of os.environ.get() to pass values, but I think something is still missing for the Python script to fetch the Jenkins build parameter.
Any help?