在Gitlab CI中将通知推送到Rocket.Chat

在Gitlab CI中将通知推送到Rocket.Chat,gitlab,gitlab-ci,rocket.chat,Gitlab,Gitlab Ci,Rocket.chat,我正在尝试通过.gitlab-ci.yml文件设置Rocket.Chat服务器的通知。我有我的测试和部署阶段工作,但我的通知阶段出错了。我按照中的说明进行了操作,但是我调整了通知脚本以使用Rocket.Chat而不是Pushbullet 这是我的.gitlab-ci.yml: stages: - test - deploy - notify test: stage: test image: homeassistant/amd64-homeassistant script

我正在尝试通过.gitlab-ci.yml文件设置Rocket.Chat服务器的通知。我有我的测试和部署阶段工作,但我的通知阶段出错了。我按照中的说明进行了操作,但是我调整了通知脚本以使用Rocket.Chat而不是Pushbullet

这是我的.gitlab-ci.yml:

stages:
  - test
  - deploy
  - notify

test:
  stage: test
  image: homeassistant/amd64-homeassistant
  script:
    - hass --script check_config -c .

deploy:
  stage: deploy
  only:
    - master
  before_script:
    - 'which ssh-agent || ( apk update && apk add openssh-client )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
    - ssh $DEPLOY_USER@$DEPLOY_HOST "cd '$DEPLOY_PATH'; git pull; sudo systemctl restart home-assistant@homeassistant"

notify_success:
  stage: notify
  allow_failure: true
  only:
    - master
  script: 
    - curl -X POST -H 'Content-Type: application/json' --data '{"text":"New Hass config deployed successfully!"}' https://chat.bryantgeeks.com/hooks/$ROCKET_CHAT_TOKEN

notify_fail:
  stage: notify
  allow_failure: true
  only:
    - master
  when: on_failure
  script: 
    - curl -X POST -H 'Content-Type: application/json' --data '{"text":"New Hass config failed. Please check for errors!"}' https://chat.bryantgeeks.com/hooks/$ROCKET_CHAT_TOKEN
我在CI Lint中得到此错误:

状态:语法不正确

错误:作业:notify_success:脚本配置应为字符串或字符串数组

如果将notify脚本行更改为在其周围带单引号('),则在CI Lint中会出现以下错误:

状态:语法不正确

错误:():分析第33行第7列的块映射时未找到所需的键

如果尝试在脚本行(“)周围使用双引号,则会出现以下错误:

状态:语法不正确

错误:():在分析第33行第5列的块集合时,未找到预期的“-”指示符


我不知道还有什么可以尝试,也不知道在哪里可以找到这一点来纠正这一点。非常感谢您的帮助。

YAML真的不喜欢字符串中的
。罪魁祸首是
'Content-Type:application/json'
中的

有时使用多行字符串格式会有所帮助,如下所示:

notify_success:
  stage: notify
  allow_failure: true
  only:
    - master
  script: |
    curl -X POST -H 'Content-Type: application/json' --data '{"text":"New Hass config deployed successfully!"}' https://chat.bryantgeeks.com/hooks/$ROCKET_CHAT_TOKEN

非常感谢,修复了它。我确实需要添加一个before_脚本,以便在容器中为该阶段安装curl。