您可以将文件传递到Azure管道吗? [英] Can you pass a file to an azure pipeline?

查看:68
本文介绍了您可以将文件传递到Azure管道吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Typescript编写的网站,该网站带有一个按钮,可触发运行天蓝色的管道.我想将某些东西从网站传递到管道作为参数,我看到了

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.

是否可以将已从.xlsx文件转换的.yaml传递到管道,并且该如何处理?为了清楚起见:网站上载了文件,我需要用户通过管道中的步骤之一传递的.xlsx文件的内容.没有后端,只有网站.

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?

推荐答案

因为您可以将.yaml结构作为对象传递给管道.您可以尝试以下解决方法.

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"
  }
}

如果必须在管道中传递yaml文件.您可以尝试将yaml文件上传到azure devops.然后在您的管道中下载yaml文件.这样管道步骤就可以访问yaml文件.

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.

以下是可用于将yaml文件上传到azure devops的可能方法.

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

1,您可以在azure devops项目中创建一个存储库来保存yaml文件.并通过您网站上的api将文件上传到存储库.参见示例这里.请参阅rest api

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.

然后,您可以在脚本任务中运行 git clone命令,以将文件下载到管道中.

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

2,您可以使用将文件上传到工作项附件.请参阅此处REST API .

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

在运行管道时,将附件ID传递给管道(您可以参考上述解决方法,并定义一个运行时参数来保存ID值).

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,将yaml文件上传到azure devops安全文件.参见此线程.

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.

希望上面有帮助!

更新:

在yaml管道文件中.您可以如下定义参数:

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'

在其余的api中.您可以按以下方式传递请求正文:

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\"}"
      }
}

然后您可以在bash任务中访问该参数,如下所示:

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

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

这篇关于您可以将文件传递到Azure管道吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆