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

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

问题描述

我有一个用 Typescript 编写的网站,该网站有一个按钮,可以触发 azure 管道运行.我想将网站中的某些内容作为参数传递给管道,我看到 here,您可以将 .yaml 结构作为 object 传递给管道.

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.

定义 运行时参数 在您的管道中保存 .xlsx 文件的值内容.见下文:

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

然后您可以使用 pipeline run rest api 在您的网站中,并在请求正文中提供 templateParameters 以使用 .xlsx 文件.见下文:

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 将文件上传到存储库.请参阅 示例 在这里.请参阅休息 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).

然后你需要调用 rest api 在您的管道中的脚本任务中获取 yaml 文件.

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.

然后使用 下载安全文件任务以在您的管道中下载 yaml 文件.

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

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

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