aws / aws/aws-codedeploy-agent

Getting an "unbound variable" error in Bash scripts

オープン
#274 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
337
フォーク
196
平均マージ
10時間 54分
マージ済み PR(30日)
4

説明

I'm getting a weird 'unbound variable' problem when I try to run my AfterInstall script. This same script works fine in Amazon Linux1 under the same environment (Ruby / RVM).

Environment:
- Amazon Linux2
- Ruby 2.5.8 (RVM)
- Latest CodeDeploy agent

This is the first part of my `config/code_deploy/after_install.sh` script. It seems to be choking on the `cd` command for some reason.
```
#!/bin/bash
set -euxo pipefail
export RAILS_ENV=$DEPLOYMENT_GROUP_NAME
cd /var/site/current
...
```

This is the error that I'm getting in CodeDeploy. I have no idea what 'unbound variable' it's trying to find.
```
LifecycleEvent - AfterInstall
Script - config/code_deploy/after_install.sh
[stderr]+ export RAILS_ENV=myenv
[stderr]+ RAILS_ENV=myenv
[stderr]+ cd /var/site/current
[stderr]+ __zsh_like_cd cd /var/site/current
[stderr]+ typeset __zsh_like_cd_hook
[stderr]+ builtin cd /var/site/current
[stderr]/opt/codedeploy-agent/deployment-root/5f156457-724d-48f6-8105-222222222222/d-11111111/deployment-archive/config/code_deploy/after_install.sh: chpwd_functions[@]: unbound variable
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず config/code_deploy/after_install.sh と CodeDeploy AfterInstall 実行ログを確認し、次に set -euxo pipefail を付けてスクリプトがどのように呼び出されるかを調べます。指定された Amazon Linux 2、Ruby、RVM 環境でコマンドを再現し、どのシェルコンテキストで未定義変数が発生するかを特定します。このエラーなしで deployment スクリプトが正常に実行されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
bash, ruby
領域
devops
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。