I'm trying to run background tasks in Codebuild using the nohup command as described in the document (https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-background-tasks.html)
Below is the buildspec I'm using
version: 0.2
phases:
build:
commands:
- nohup sleep 30 & echo $! > pidfile
- wait $(cat pidfile)
I get an error for this as below
[Container] 2021/08/25 06:04:40 Running command wait $(cat pidfile)
/codebuild/output/tmp/script.sh: line 4: wait: pid 207 is not a child of this shell
[Container] 2021/08/25 06:04:40 Command did not exit successfully wait $(cat pidfile) exit status 127
[Container] 2021/08/25 06:04:40 Phase complete: BUILD State: FAILED
I do not understand why the wait command i being executed in a different shell. Is there any way how I can make this execute in the same shell or am I doing it wrong?