I have a problem with a python script I call from a Jenkins pipeline. In the main script I have this:
import sys
authentication = sys.argv[1]
style = sys.argv[2]
ip = sys.argv[3]
accounting = sys.argv[4]
PrintTestCases([str(authentication), str(style), str(ip), str(accounting)])
The function PrintTestCases is in another file and use a match-case structure
def PrintTestCases(authentication, style, ip, accounting):
match accounting:
case "NOACC":
match [authentication, style, ip]:
case ['NONE', 'NONE', 'NONE']:
print("Test Case Number 1")
case _:
print("Wrong Test Case")
case "ACC":
match [authentication, style, ip]:
case ['PRIVATE', 'NONE', 'NONE']:
print( "Test Case Number 2")
case _:
print("Wrong Test Case")
Then I call the main script from a Jenkins pipeline like this
python3 -u main NONE NONE NONE ACC
But I always get this error
PrintTestCases() missing 3 required positional arguments: 'style', 'ip', and 'accounting'
Based on my understanding, I am passing the argument to the function via the sys.argv Why the function does not see the required arguments?
You are passing a list that contains all the arguments. Note how these two differ.
PrintTestCases([str(authentication), str(style), str(ip), str(accounting)])
and
PrintTestCases(str(authentication), str(style), str(ip), str(accounting))
In the first case, you're passing a single object. Use the second.
PrintTestCases
is expecting 4 distinct arguments, but by passing [str(authentication), str(style), str(ip), str(accounting)]
you're actually giving this list as the authentication
argument alone, with the others unfilled.