How to add operation in yaml? - Azure Pipeline
I have this python file (calculator) stored in my repository.
In order for that to execute, parameters in the python file should be received.
One parameter is defined as an if-else condition in the python code. ---> operation
I need to, declare that parameter in yaml file. Since its an operation expression, I need to do it in the yaml.
Here's the py:
if operation == "add":
IP = address
else if operation == "delete":
IP's= IP's + "," + address
else:
print("error")
return 1
def execute():
try:
parser = argparse.ArgumentParser(desc='calculates')
parser.add_argument('value1', help='input value 1')
parser.add_argument('value2', help='input value 2')
parser.add_argument('operation', help='add or remove')
args = parser.parse_args( )
return total(args.value1, args.value2, args.operating_mode)
operation cannot be declared as a parameter.
I believe it should be in the yml file. once paramete开发者_开发问答rs are received, python file will execute the processPlease see whether using parameters and the PythonScript@0 Task can meet your requirement.
I have the python file in repo, here call it 'py' file
Then create and edit the azure-pipelines.yml like this:
parameters:
- name: operation
displayName: operation
type: string
values:
- delete
- add
- others such as restore
- others such as push
steps:
- script: echo ${{ parameters.operation }}
- task: PythonScript@0
inputs:
scriptSource: 'filePath'
scriptPath: '$(System.DefaultWorkingDirectory)/py'
Then when you run the pipeline, it will let you choose the values in the drop list:
You could see the value from '- script: echo ${{ parameters.operation }}' this step. Then the task will go to repo branch(here in my sample main branch) and find the file called py to execute.
I hope it could help.
精彩评论