Query Jenkins Server API for jobs matching filter / regex & clone all git repos
1.2K
A Ruby Script to query a Jenkins Server and find the jobs matching a particular filter.
Get the Git clone URL of each job and check them out to /tmp/src.
GIT_CLONE_DIR: Checkout repo to this directory inside the Docker Container./Users shared directory from Host Mac -> Docker Host VM)GIT_CLONE_USER: Checkout repo using this SSH username.git clone ssh://${GIT_CLONE_USER}@host:port/path)GIT_CLONE_FQDN: Default FQDN to use for short hostnames found for git repo URIs.JENKINS_DEBUG: Turns on extra info debug logging.JENKINS_HOST: Jenkins Host to query for job list.JENKINS_JOB_FILTER: A regex to filter what jobs to search for Git URIs.@client.job.list(jobs_to_filter) from jenkins_api_client)JENKINS_PASSWORD: Jenkins API Access Token.http://jenkins.yourdomain.example.net/me/configureJENKINS_PORT: Port to access Jenkins API on.JENKINS_USER: User to access Jenkins API with.You will need an API token from your Jenkins Server to use this script. To obtain one:
Show API Token..."Use the API Token as JENKINS_PASSWORD when running the container.
To checkout all repos listed in Jenkins Jobs matching 'foo' to ~/src on the Docker Host, run:
docker run -ti -e JENKINS_HOST=jenkins.example.net -e JENKINS_USER=myjenkinsuser -e JENKINS_PASSWORD=1deadbeefbadc0de123456789abcd -e JENKINS_JOB_FILTER='foo' -v ~/src/:/tmp/src trinitronx/jenkins-job-batch-git-clone
To checkout all repos listed in Jenkins Jobs matching 'foo' to /Users/myboot2dockeruser/src in the Docker Container, run:
docker run -ti -e GIT_CHECKOUT_DIR=/Users/myboot2dockeruser/src -e JENKINS_HOST=jenkins.example.net -e JENKINS_USER=myjenkinsuser -e JENKINS_PASSWORD=1deadbeefbadc0de123456789abcd -e JENKINS_JOB_FILTER='foo' -v ~/src/:/tmp/src trinitronx/jenkins-job-batch-git-clone
To run in debug mode (shows extra info):
docker run -ti -e JENKINS_DEBUG=1 -e JENKINS_HOST=jenkins.example.net -e JENKINS_USER=myjenkinsuser -e JENKINS_PASSWORD=1deadbeefbadc0de123456789abcd -e JENKINS_JOB_FILTER='foo' -v ~/src/:/tmp/src trinitronx/jenkins-job-batch-git-clone
To run in debug mode & test repo checkout only inside Docker Container's /tmp/src directory (doesn't checkout files to the Docker Host):
docker run -ti -e JENKINS_DEBUG=1 -e JENKINS_HOST=jenkins.example.net -e JENKINS_USER=myjenkinsuser -e JENKINS_PASSWORD=1deadbeefbadc0de123456789abcd -e JENKINS_JOB_FILTER='foo' trinitronx/jenkins-job-batch-git-clone
If cloning via SSH URI, or private repos git credentials can prevent an easy batch clone. You will need to pass through your git SSH keys, or use ssh-agent. In the case of GitHub, you may choose to use a GitHub API Token.
A good place to start is to run ssh-agent on either the Docker Host machine, or on the Hosting physical machine that is running boot2docker or docker-machine. You will then need to pass through the $SSH_AUTH_SOCK environment variable, and mount the actual socket file as a docker volume into the Docker Container. The method for doing this depends on where you are running the docker daemon (e.g.: boot2docker on a Mac / physical machine, docker-machine on a Mac / physical machine, inside another Linux VM, on a physical machine, etc...)
Here are some helpful methods:
Content type
Image
Digest
sha256:de2d5f798…
Size
278.6 MB
Last updated
over 8 years ago
docker pull trinitronx/jenkins-job-batch-git-clone