Passing jenkins "parameters" to python subprocess module

Jenkins setup:

Jenkins: 2.401.2
OS: Linux - 5.4.0-156-generic
Java: 11.0.19 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)

How can I pass a parameter named “FILENAME” that is defined under jenkins “This project is parameterized” inside of a python script? The script is like the one below:

$ cat python-script.py
#!/usr/bin/python3
import os
import subprocess
result = subprocess.run([“ls”, “$FILENAME”])
result

Here the script should run “ls -l /etc/passwd”

Regards,
Niranjan

Parameters are available as environment variables

1 Like