我有以下curl 请求,我想在我的CircleCI 管道的config.yml 文件中使用它。
但它一直给我错误,我找不到正确的语法来让它工作。我将文件放入 YAML lint 中,错误是在此上下文中不允许映射值。这是我的卷曲请求
curl -X POST -H 'Content-type: application/json' --data '{"text":"This is a test!"}' [WEBHOOK URL]
Run Code Online (Sandbox Code Playgroud)
这是我的 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
Run Code Online (Sandbox Code Playgroud)
使用折叠块标量:
\nversion: 2.1\n\njobs:\n build:\n working_directory: ~/circleci-python\n docker:\n - image: "circleci/python:3.6.4"\n steps:\n - checkout\n - run: python3 main.py\n test:\n working_directory: ~/circleci-python\n docker:\n - image: "circleci/python:3.6.4"\n steps:\n - checkout\n - run: python3 main-test.py \n - run: >-\n curl -X POST -H \'Content-type: application/json\'\n --data \'{"text":"This is a test!"}\' [WEBHOOK URL]\nworkflows:\n build_and_test:\n jobs:\n - build\n - test:\n requires:\n - build\nRun Code Online (Sandbox Code Playgroud)\n>启动折叠块标量。以下内容-告诉 YAML 去除最后的换行符,否则该换行符将成为值的一部分。
块标量不使用引号或转义序列,并在保留其缩进级别时结束。它们非常适合输入使用类似于 YAML 的语法的值。折叠块标量将行折叠成一个空格,这允许您将命令分成多行,就像我在这里所做的那样。
\n您收到错误的原因是 YAML 读取curl -X POST -H \'Content-type为隐式键 \xe2\x80\x93 将其视为行中的b- a: b: c。YAML 语法不允许这样做。卷曲行中的单引号不会阻止这种情况,因为未加引号的标量内的引号仅被解析为内容而无需任何特殊规则。
| 归档时间: |
|
| 查看次数: |
11281 次 |
| 最近记录: |