dockershellbuildkite

Buildkite use shell variables in global hook


I used a variable in my pipeline script like this.

# This shell is a pipeline shell script

export container_id=`docker run -d MY_CONTAINER`

then regardless of the success of the result, I want to remove my container using container_id, like this.

# This shell is a global exit hook

docker rm ${docker stop $container_id}

but it does not work. What can I do to solve this problem?


Solution

  • Use command substitution:

    docker rm $(docker stop $container_id)