我正在使用 gitlab ci jobs 在更新分支时自动执行我的 aws iot 设置。
我的gitlab-ci.yml:
name: hashicorp/terraform:light
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
- rm -rf .terraform
- terraform --version
- terraform init
stages:
- validate
- plan
- apply
validate:
stage: validate
script:
- terraform validate
plan:
stage: plan
script:
- terraform plan
dependencies:
- validate
apply:
stage: apply
script:
- yes yes | terraform apply
dependencies:
- plan
when: manual
在 terraform apply 作业中,一切运行成功,但作业仍然退出并出现错误代码 141。 这些是 terraform apply debug 的最后几行:
local_file.water_switchCert: Creation complete after 0s [id=1085d628417927a07dac038743969c1127b4fd0d]
local_file.sensor_2_key: Creation complete after 0s [id=d9952a9eb0d990b5c6e34fda74a29785c62dcd56]
local_file.water_switchKey: Creation complete after 0s [id=b05acd1ef2aa31b8493ee30a461164aa3ddd55ca]
Apply complete! Resources: 8 added, 0 changed, 0 destroyed.
Running after_script
00:01
Uploading artifacts for failed job
00:02
ERROR: Job failed: exit code 141
我真的不知道为什么会出现这种行为。也许有人经历过同样的问题并可以提供帮助,我们将不胜感激
我在 Gitlab CI 综合中遇到了类似的问题,我想登录我的私人 npm 注册表。我使用了
yes '' | npm login
命令。它成功登录,但管道失败,并显示错误代码 141。将代码更改为 (yes '' || true) | npm login
对我有用。问题的出现是因为 yes 命令生成的 yes 字符串比 terraform apply 真正需要的多。所以 stdin 由 yes 命令操作。将其设置为 true,可确保只有必要的“是”输入才会进入标准输入。因此将脚本重新连接为:
(yes yes || true) | terraform apply
@foad322 的回答解决了我的问题