I am using the node image to create the .tags file for use in the build step with the plugins/docker image. The build works each time, but I would say about 50% of the time the .tags file is not created. I can run the same build and one time it works and the next time it does not. There are no errors in the drone or runner container logs.
Wondering if anyone else has seen this and what your workaround you came up with. Not sure if this is an issue with the node, drone, or runner container or something else.
Relevant part of .drone.yml
- name: tag
image: node
volumes:
- name: cache
path: /drone/src/
commands:
- echo -n "$(date +'%Y-%m-%d_%H-%M')_${DRONE_COMMIT}, latest" > .tags
- pwd
- ls -al
- more .tags
This is definitely strange behavior. Is there any chance that when the .tags file isn’t written, it is a different type of event? Perhaps a promotion event, or something else, where the environment is slightly different?
My only other thought is maybe the steps are going so quickly that the file hasn’t actually been written by the time the next step runs? Maybe try running the sync command immediately after you create the .tags file?
I added sync just after the echo command. That had no effect. The whole task only takes 2 seconds. I added a sleep 5 before and after the sync and that had no effect either. I have this same step in 11 repos all having the same symptoms.
I am guessing this is an issue with the node container. I will try a different container and see if that has any impact when I get some time.
I switched to an ubuntu container and experience the same results. I am able to run the echo command without piping to the .tags file and it displays to the console as expected. I also added touch .tags and the file is created before the echo.
I switched to “tags: ${DRONE_COMMIT} , latest” in the build step and removed the tag step. That works consistently. Would prefer a date as the tag, but better than nothing.
The above snippet in your yaml is the problem and should be removed. Drone automatically creates a volume at /drone/src and mounts into every pipeline step. You are creating a new volume at the same path, and it is clashing with the Drone volume which is leading to unepected behavior.
You can learn more about the workspace volume in the Drone docs:
Drone automatically creates a temporary volume, known as your workspace, where it clones your repository. The workspace is the current working directory for each step in your pipeline. The default workspace path is /drone/src .
My bad. Removing it has no impact. It was not in there to begin. I added it trying different things to troubleshoot and get it to work consistently. Below is what I believe should work with the tag step uncommented and the tag setting in the build step commented out.
The problem I see with the yaml you provided is that you define tags in the yaml. The values in the yaml take precedence over values defined in the file. The file is therefore ignored.
I also ran a quick test that you can use as a reference, with screenshots provided below. Note that we write a tag value to the file and the file is used by the subsequent step to tag the image. I am unable to reproduce any issues and have not received any other reports of issues with regards to this feature (which has been around for a few years now).
I am only specifying the tags in the build step when the tag step is commented out. Never doing both at the same time. If I test the tags step, I comment out the tags in the build step.
The issue I am having is that the file never gets created in the tags step, not that is is created and is not being read. If I add an ls to the tag step, the file is not listed there, but the files from the repo I cloned are.
I have been able to get the file to be created reliably every time by putting it in a while loop to check to see if it exists and if not create it. I am guessing it is some type of timing issue. The more of the .tags file works about 50% of the time I would say. Sometimes it shows nothing and other times it shows the contents of the file. When it does not show the contents of the file, the image is properly tagged with the contents of the file. Guessing it moves to the next step before it successfully captures the output of the command to the log. I am now using the alpine image, but I would guess this will also work in the node and ubuntu images as well.
- name: tag
image: alpine
commands:
- while [ ! -f .tags ]; do echo -n "$(date +'%Y-%m-%d_%H-%M'), latest" > .tags; done;
- ls -al /drone/src/
- more .tags