Azure Pipelines`-script:...

发布于 2025-02-04 00:03:08 字数 992 浏览 5 评论 0原文

我正在寻找一种制作多行脚本的方法:

steps:
  - script: >
      echo foo
      bar

结果:

foobar

没有空间或新线。


在实际情况下,我正在定义一个类似的变量:

  - script: >
      echo
      "##vso[task.setvariable variable=packageVersion]
      some_very_long_awk_code_to_generate_a_3_digit_number"

此问题导致它包含一个空间,因此存储的变量将变为some_very _..vey _...(请注意开始时的空间)。 “>”脚本旁边会添加有新线的空间,但是似乎没有任何方法可以在没有空间或新线的情况下加入它。

有关Yaml Multiline Code 的解释解释它应该如下:

steps:
  - script: >
      echo foo\
      bar

,这也会导致:

foo bar

不幸的是:不幸的是 Quote:

steps:
  - script: >
      echo "foo\
      bar"

将导致:

foo\ bar

I am looking for a way to make a multiline script like:

steps:
  - script: >
      echo foo
      bar

result in:

foobar

with no spaces or newlines.


In the real-world scenario I am defining a variable like so:

  - script: >
      echo
      "##vso[task.setvariable variable=packageVersion]
      some_very_long_awk_code_to_generate_a_3_digit_number"

This issue is causing it to include a space, so the stored variable will become some_very_... (note the space at the start). The ">" next to the script will add spaces where there are newlines, but there seems to be no method to just join it without a space or newline.

This explanation about YAML multiline code explains that it should work as follows:

steps:
  - script: >
      echo foo\
      bar

Unfortunately, this also results in:

foo bar

Performing it with a double quote:

steps:
  - script: >
      echo "foo\
      bar"

will result in:

foo\ bar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶茶白久 2025-02-11 00:03:08

azure-Pipelines - 脚本:...不支持没有空格的多行代码,没有newlines

文档 YAML多行代码用于参数,但这在输出语法echo中不起作用。

当您使用启动器pipline创建默认的yaml管道时:

steps:

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

​尝试使用以下脚本:

- script: |
    echo foo
    echo bar

Azure-pipelines - script: ... does not support multiline code with no spaces and no newlines

The document about YAML multiline code is used for parameter, but this doesn't work in the output syntax echo.

And when you create a default YAML pipeline with Starter piepline:

enter image description here

There is a demo code about multi-line script:

steps:

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

So, if you want make a multiline script, you could try to use below scripts:

- script: |
    echo foo
    echo bar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文