aws / aws/aws-codedeploy-agent
Getting an "unbound variable" error in Bash scripts
- Vorherrschende Sprache
- Rust
- Sterne
- 337
- Forks
- 195
- Ø Merge
- 10 Std. 54 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
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
```
Beitragsleitfaden
Rechercherichtung
Beginne mit config/code_deploy/after_install.sh und dem CodeDeploy AfterInstall-Ausführungsprotokoll und untersuche anschließend, wie das Skript mit set -euxo pipefail aufgerufen wird. Reproduziere den Befehl in der angegebenen Amazon Linux 2-, Ruby- und RVM-Umgebung und ermittle, welcher Shell-Kontext die nicht gesetzte Variable erzeugt; abgeschlossen ist die Aufgabe, wenn das Deployment-Skript ohne diesen Fehler erfolgreich ausgeführt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- bash, ruby
- Bereich
- devops
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100