1

I am trying to pass to a python scripts 3 parameters one of them is an array, this works when i run the script locally, i am using sys.argv to achieve this.

However the argument field support only strings as far i can see. How can i go around this any ideas? Thanks

the array is ${{ parameters.packageVersion }}

Code:

  - task: PythonScript@0
    displayName: 'Modify ansible inventory files (wms_common.yml) with deployed versions'
    inputs:
      scriptSource: filePath
      scriptPath: deployment/s/azure-devops/scripts/script.py
      arguments: |
          ../../inventories/${{ variables.inventory }}/group_vars/all/wms_common.yml
          ../../inventories/central/${{ variables.inventory }}/group_vars/all/wms_common.yml
          ${{ parameters.packageVersion }}

Error:

/azure-devops/wms.full.pipeline.yml (Line: 95, Col: 18): Unable to convert from Array to String. Value: Array

Edit: Reframed question

1 Answer 1

0

I think the below YAML will help you convert the array to String objects and use them.

variables:
  myVariable1: 'value1'
  myVariable2: 'value2'
  system.debug: true

parameters:
- name: InstanceArgs 
  type: object
  default: [1,2] 

steps:
- task: PythonScript@0
  inputs:
    scriptSource: 'inline'
    script: |
        import argparse 

        parse = argparse.ArgumentParser(description="Test")
        parse.add_argument("test1")
        parse.add_argument("test2")
        args = parse.parse_args()
        print(args.test1)
        print(args.test2)
        print('this is a test.')
    # arguments: $(myVariable1) $(myVariable2)'
    arguments: ${{join(' ',parameters.InstanceArgs)}}

You need to use the join expression in YAML to get the elements:

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#join

enter image description here

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

1 Comment

thanks, i didn't have to modify the code to use argparse, i just used the join expression on my third parameter, and then edited my script to seperate them to array again, thanks for the idea. So join was the solution

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.