Molecule does not randomize the instance name
It’s of course possible to launch multiple tests in parallel but if you use the same instance name in all
your molecule.yml
file, they will collide and fail.
To avoid this potential problem, it’s possible a find a unique name by using the environment variable expansion feature.
In the platform block, where the instance name is defined, just include a variable:
platforms:
- name: 'target-debian-${MOLECULE_INSTANCE_NAME_ID:-1}'
Before a run, just export the MOLECULE_INSTANCE_NAME_ID variable with a random content.
It’s the same mechanism: just export the MOLECULE_INSTANCE_NAME_ID.
For GitHub Actions, use the github.run_id
variable:
- name: Test with molecule
env:
MOLECULE_INSTANCE_NAME_ID: '${{ github.run_id }}'
run: |
molecule test -s docker_${{ matrix.distribution }}
For Gitlab CI, use the CI_JOB_ID
variable:
variables:
MOLECULE_INSTANCE_NAME_ID: "$CI_JOB_ID"