在 Gitlab CI 中将通知推送到 Rocket.Chat
Push Notifications to Rocket.Chat in Gitlab CI
我正在尝试通过我的 .gitlab-ci.yml 文件向我的 Rocket.Chat 服务器设置通知。我有我的测试和部署阶段工作,但我的通知阶段出错了。我遵循了 here 的说明,但我调整了通知脚本以使用 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 中收到此错误:
Status: syntax is incorrect
Error: jobs:notify_success:script config should be a string or an array of strings
如果我将通知脚本行更改为在其周围加上单引号 ('),我会在 CI Lint 中收到以下错误:
Status: syntax is incorrect
Error: (): did not find expected key while parsing a block mapping at line 33 column 7
如果我尝试在脚本行 (") 周围加上双引号,我会收到以下错误:
Status: syntax is incorrect
Error: (): did not find expected '-' indicator while parsing a block collection at line 33 column 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
我正在尝试通过我的 .gitlab-ci.yml 文件向我的 Rocket.Chat 服务器设置通知。我有我的测试和部署阶段工作,但我的通知阶段出错了。我遵循了 here 的说明,但我调整了通知脚本以使用 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 中收到此错误:
Status: syntax is incorrect
Error: jobs:notify_success:script config should be a string or an array of strings
如果我将通知脚本行更改为在其周围加上单引号 ('),我会在 CI Lint 中收到以下错误:
Status: syntax is incorrect
Error: (): did not find expected key while parsing a block mapping at line 33 column 7
如果我尝试在脚本行 (") 周围加上双引号,我会收到以下错误:
Status: syntax is incorrect
Error: (): did not find expected '-' indicator while parsing a block collection at line 33 column 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