Use scale number from container in docker-compose.yml

Hello,

We use docker for our Jenkins-buildslaves and want to use rancher for scaling and recreating the slave-containers. As we use the Jenkins-swarm-plugin we need an environment variable for labeling them in a unique way.

docker-compose.yml:

 [...]
 environment:
   JENKINS_SLAVE_NAME:   buildslave-01
 [...]

We need to adapt the Jenkins_slave_name due to the name of the docker-container. We cannot find any environment variable to get these information though.
we thought we could use something like the variables you can define in the rancher-compose file, but the scaling function doesn’t adapt these variables.

Is there a trick to get that information? It doesn’t necessarily have to be the whole name, the number would be sufficient.

Environment variable substitutions are not evaluated per-individual container. One way you can do this is to have the entry point talk to rancher-metadata and get info about itself, which has various things you could use like the container’s name and createIndex.

Do you really need exact slave name ? Slave with same tag/flag need to be same, there is normally no need to have exact slave name and scale it. See how jenkins swarm plugin works, I used several types of Jenkins agents with labels and scale just needed selected farm/service.