Reputation: 6333
Background:
The Jenkins plugins I'm working with are:
The company I work for is using Jira + Bitbucket.
I've implemented automatic builds in Jenkins by creating a Jenkins "Bitbucket team" job which automatically scans the whole company's Bitbucket organization repositories and all branches within each repository and automatically builds jobs for each branch within each repository.
Once a pull request is opened or a commit is pushed to one of these repositories, Jenkins triggers a build for that branch and that pull request respectively.
The Jenkinsfile
of the pipeline is identical on all repositories.
The job has some stages which require running Docker and for that there's a Jenkins slave installed with Docker.
One of the stages is running docker-compose
and for that it requires a docker-compose.yml
file which resides in the repository.
Now my problem:
The job which is responsible for the scanning of the BitBucket organization resides on the Jenkins master which means that the first checkout is done in the Jenkins master workspace while one of the main stages of the build (the docker-compose
) takes place on the Jenkins slave "Docker" machine so when it gets to that stage the files from the repository are missing there, so I use checkout scm
again within the node('docker'){}
to pull the newly committed files into the docker machine workspace.
That means that the repository is cloned twice; once by the scanning job which identifies the commit/PR - into the Jenkins master's workspace and a second time by the Jenkins docker slave into it's workspace.
For now the company's repositories are not that large but they could become large in the future and I want to make sure that the jobs are finishing their run as soon as possible.
So I was wondering if it's possible to somehow override "BitBucket plugin" to check out only Jenkinsfile from the branch where the commit/PR has been done instead of the whole branch.
Is such a thing possible?
Upvotes: 4
Views: 3715
Reputation: 38826
In the pipeline options you can set skipDefaultCheckout
.
Skip checking out code from source control by default in the
agent
directive. For example:options { skipDefaultCheckout() }
Then it will discover (and run) your Jenkinsfile, but not automatically checkout the whole branch.
Upvotes: 2
Reputation: 693
If you want to check out a single file you can do that in a shell with this command:
git archive --remote=git@git.xxx.xxx:project/your-repo.git HEAD:folder file | tar -x
Upvotes: 0