Can you pass a file to an azure pipeline?

我们两清 提交于 2021-02-05 11:30:13

问题


I have a website written in Typescript that has a button which triggers an azure pipeline to run. I would like to pass something from the website to the pipeline as a parameter and I saw here that you can pass a .yaml structure as object to a pipeline.

Is it possible to pass a .yaml that was converted from an .xlsx file to the pipeline and how would one go about that? For clearance: The website has a file upload and I need the content of the .xlsx-file the user passes in one of the steps in the pipeline. There is no backend, just the website.

If that's not possible, how should I do it?


回答1:


Since you can pass a .yaml structure as object to a pipeline. You can try below workaround.

Define Runtime parameters in your pipeline to hold the value contents of the .xlsx-file. See below:

parameters:
- name: contentKey
  displayName: Pool Image
  default: contentDefaultValue

Then You can use pipeline run rest api in your website and provide the templateParameters in the request body to override the Runtime parameters defined in your pipeline with the contents of the .xlsx-file. See below:

{
  "templateParameters":{
     "contentKey": "contentValue"
  }
}

If you have to pass the yaml file in the pipeline. You can try to upload the yaml file to azure devops. And then download the yaml file in your pipeline. So that the pipelines steps can access the yaml file.

Below are the possible methods you can use to upload the yaml file to azure devops.

1, you can create a repository in your azure devops project to hold the yaml file. And upload the file to the repository via api in your website. See example here. See rest api here.

Then you can run git clone command in a script task to download the file in your pipeline.

2, you can use upload the file to workitem attachment. See rest api here.

And pass the attachment id to the pipeline when your run the pipeline(you can refer to above workaround and define a Runtime parameters to hold the id value).

Then you need to call rest api to get the yaml file in a script task in your pipeline.

3, Upload the yaml file to azure devops secure file. See this thread.

Then use download secure file task to download the yaml file in your pipeline.

Hope above helps!

Update:

In yaml pipeline file. You can define your parameter as below:

parameters:
  - name: paramname
    type: object
    displayName: 'configure path'
    default: 
      param1: '[{\"a\":\"x\",\"b\":\"y\"},{\"a\":\"x\",\"b\":\"y\"}]'
      param2: 'string1'
      param3: 'string2'

In the rest api. You can pass the request body as below:

{
  "templateParameters":{
        "paramname": "{\"param1\":\"'[{\\'a\\':\\'x\\',\\'b\\':\\'y\\'},{\\'a\\':\\'x\\',\\'b\\':\\'y\\'}]'\",\"param2\":\"string11\", \"param3\":\"string22\"}"
      }
}

Then you can access the parameter in the bash task like below:

 echo "${{parameters.paramname.param1}}"
 echo "${{parameters.paramname.param2}}"


来源:https://stackoverflow.com/questions/63922636/can-you-pass-a-file-to-an-azure-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!