I have a java application in gradle. I have managed to setup an agent running on Linux (with docker socket volume attached) and the pipeline has a simple step of uploading the pipeline.yml file.
However when it runs, it always says that gradlew file could not be found. Iâve validated that it does exist when buildkite clones the repo, so I am really not sure what else it could be. Iâve tried the example on the docs of using docker-compose, and that does not work either.
Hope youâre well and welcome to the Buildkite Forum!
Whatâs happening here is that by default; images that are run by the Docker plugin donât automatically have the current Buildkite build directory mounted (by default, the Docker plugin works in the /workdir directory within the spun up container, this can be changed however).
Assuming that this is a standard Gradle application with gradlew script within the root directory within the cloned repository on the build host: mounting it like so should suffice with a clean build/other Gradle action:
Thank you for replying fast and with the information.
I am still seeing the issue however. First I tried and I get docker: invalid spec: :/workdir: empty section between colons., so I changed ${pwd} to ${PWD} which made that go away. But, I am still seeing the issue as before:
sh: can't open 'gradlew': No such file or directory
I have tried using the jdk21-alpine image instead and setting the command to ls to see if it would list the files, the build succeeds but ls shows nothing, so still seems like it has nothing in the directory its working in
Hmm thats quite interesting; the pluginâs default working directory can be changed if its needed, just defaults to /workdir in unspecified scenarios if youâd potentially like it to be changed. What host OS is this being cloned into/run on? For reference. my example did use gradle:jdk17 but it should be similar for upper versions.
On the mounting; are you running an ls in the same container as the .gradlew command - something akin to command: ls && sh ./gradlew clean build? The files cloned in on the host (checkout hook) should be mapped over through the volume mount as above.
Assuming that the above wrapped Dockerfile is the agent thats spun up on the host that that is also registered with Buildkite and from which it is running said steps; weâll have a Docker-in-Docker scenario.
Are you able to run the actual agent bootstrap on the actual host OS that said image above runs? From there; it will run the actual gradle:jdk21 image as a container; rather than the agent container itself that is pulling the Gradle image in/running it in an embedded container.
From the first premise; my tests above were on a Mac running host (would be similar for others like Ubuntu etc) - for which the actual agent was running on and creating said Gradle container/mounting the checked out repository with the Gradle artefacts
So instead of running the docker image of the agent, I am running it as per the docs for Linux directly on the OS and it now works - so it seems like the issue was with what I had configured for the agent.
Its more the case as I thought above; where if you were running the agent on the host itself as a container; it technically can accept work etc as per normal, its more just the case where other images are ran inside that; DinD - and volume mounting between these layers - which can be a bit tricky to navigate!
Glad to have helped, let us know if anything else arises