In our jenkins2 pipeline we use docker-compose for some of our tests and our docker-compose file gets its network name from a combination of the branch name (git) and its build number.
Jenkins file fragment:
def version = "$BRANCH_NAME-$BUILD_NUMBER"
def networkName = "network-$version"
sh "NETWORK_NAME=$networkName docker-compose up -d"
docker-compose.yml fragment:
version: '3.5'
networks:
default:
name: ${NETWORK_NAME}
driver: bridge
It looks like when we have a short branch name everything goes fine and when we have a long branch name it fails.
How long can the network name be in docker-compose? I can't seem to find it in the documentation. Is there a better solution to get unique network names than going for the branch name?
I've tried this but it seems totally overkill somehow:
echo $(git rev-parse --abbrev-ref HEAD) | md5 | cut -f1 -d" "
will give md5 result.