Ant not working with Jenkins within a Docker conta

2019-07-28 02:55发布

问题:

I want to have my Jenkins CI in a Docker container.

I've pulled the Jenkins Docker image and started it following the documentation:

sudo docker run -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home jenkins

Jenkins is started okay, I configure the job for the project using Ant as build tool.

When I run the job, Jenkins throws the following error regarding to Ant (regardless the configured build target):

ERROR: command execution failed.Maybe you need to configure the job to choose one of your Ant installations?

But, if I go to the workspace directory of the build (/var/jenkins_home/workspace/my_job/) and execute the same target, I get no error:

ant clean

What am I doing wrong?

回答1:

As @izzekil has pointed, Ant was not installed inside the container, but only in the host machine.

It has been enough to install Ant in the container (running with root user):

sudo docker run -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home -u root jenkins

And then:

sudo docker exec <container_id> apt-get update
sudo docker exec <container_id> apt-get install ant -y