作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 curl 请求,我想在我的 CircleCI 管道的 config.yml 文件中使用它。
但它一直给我错误,我找不到正确的语法来让它工作。我将文件放在 YAML lint 中,错误是在此上下文中不允许映射值。这是我的 curl 请求
curl -X POST -H 'Content-type: application/json' --data '{"text":"This is a test!"}' [WEBHOOK URL]
这是我的 config.yml 文件:
version: 2.1
jobs:
build:
working_directory: ~/circleci-python
docker:
- image: "circleci/python:3.6.4"
steps:
- checkout
- run: python3 main.py
test:
working_directory: ~/circleci-python
docker:
- image: "circleci/python:3.6.4"
steps:
- checkout
- run: python3 main-test.py
- run: curl -X POST -H 'Content-type: application/json' --data '{"text":"This is a test!"}' [WEBHOOK URL]
workflows:
build_and_test:
jobs:
- build
- test:
requires:
- build
最佳答案
使用折叠 block 标量:
version: 2.1
jobs:
build:
working_directory: ~/circleci-python
docker:
- image: "circleci/python:3.6.4"
steps:
- checkout
- run: python3 main.py
test:
working_directory: ~/circleci-python
docker:
- image: "circleci/python:3.6.4"
steps:
- checkout
- run: python3 main-test.py
- run: >-
curl -X POST -H 'Content-type: application/json'
--data '{"text":"This is a test!"}' [WEBHOOK URL]
workflows:
build_and_test:
jobs:
- build
- test:
requires:
- build
>
开始折叠 block 标量。以下 -
告诉 YAML 去除最后的换行符,否则它会成为值的一部分。
block 标量不使用引号或转义序列,并在离开缩进级别时结束。它们非常适合输入使用类似于 YAML 的语法的值。折叠 block 标量将行折叠成一个空格,这样您就可以将命令分成多行,就像我在这里所做的那样。
出现错误的原因是 YAML 将 curl -X POST -H 'Content-type
读取为隐式键 - 将其视为行中的 b -a:b:c
。 YAML 语法不允许这样做。 curl 行中的单引号不会阻止这种情况,因为未加引号的标量内的引号仅被解析为内容,没有任何特殊规则。
关于curl - 如何在 yml 中运行 curl 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68268869/
我是一名优秀的程序员,十分优秀!