buildkite / docker-buildkite-agent

Previous home of buildkite/agent docker image scripts
26 stars 14 forks source link

Setting BUILDKITE_AGENT_NAME in v3 doesn't interpolate name properly #48

Open toolmantim opened 7 years ago

toolmantim commented 7 years ago

In the v3 tag of this image, if you set a custom agent name using -e BUILDKITE_AGENT_NAME=agent-%n, when the bootstrap runs instead of it getting the interpolated version that's handed to the agent from the backend during registration process (agent-1 or agent-2, etc) it receives agent-%n.

Because of this, the checkout directory is /buildkite/builds/agent--n, which clashes with other agents if they all mount the same builds directory (which you're meant to be able to).

Strangely this problem isn't present in the non-Docker version, or in v2 of the image.

For v3:

docker run \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e BUILDKITE_AGENT_NAME='agent-name-test-%n' \
  buildkite/agent:3 start \
    --token xxx \
    --meta-data agent-name-test

The bootstrap gets BUILDKITE_AGENT_NAME=agent-name-%n in this case. ​ v2 with env works AOK:

​docker run \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e BUILDKITE_AGENT_NAME='agent-name-test-%n' \
  buildkite/agent start \
    --token xxx \
    --meta-data agent-name-test

And v3 with --name argument works AOK:

docker run \
  -v /var/run/docker.sock:/var/run/docker.sock \
  buildkite/agent:3 start \
    --token xxx \
    --meta-data agent-name-test \
    --name 'agent-name-test-%n'