Pipeline: How to cache downloaded (gradle) dependencies using Docker SSH Slave

1,458 views
Skip to first unread message

Marco Pas

unread,
Jun 22, 2016, 7:48:56 AM6/22/16
to Jenkins Users
Now that we have a first successful build using a Jenkinsfile Pipeline we are looking on how to cache downloaded dependencies.
Currently when we build our Gradle applications the dependencies are downloaded each time the Docker Slave is executed on a remote host. Is there a way to cache the downloaded dependencies for later reuse so we can speedup the build process?

- Marco

Craig Rodrigues

unread,
Jun 23, 2016, 2:48:32 AM6/23/16
to Jenkins Users
In 2011, this discussion thread talked about this topic: https://discuss.gradle.org/t/cache-dependencies-into-local-maven-repository-from-gradle/7525 and it didn't seem possible.

However, I advise you to post your question to https://discuss.gradle.org/ , because there may be new information that can make this possible.

--
Craig

Marco Pas

unread,
Jun 23, 2016, 3:00:56 AM6/23/16
to Jenkins Users, rod...@freebsd.org
I was hoping that these dependencies could be cached somewhere in the workspace instead or relying on Gradle specific things. We have the same thing for NPM related dependencies. Continuous downloading of the related dependencies is just to slow.

Peter Hayes

unread,
Nov 26, 2016, 8:16:26 AM11/26/16
to Jenkins Users, rod...@freebsd.org
Jumping on an old thread but I have the same need using docker based agents.  I was thinking of trying to write a cache plugin that achieves a similar caching capability that travis ci provides for arbitrary directories : https://docs.travis-ci.com/user/caching/#Arbitrary-directories

In the pipeline code, there would be a cache build wrapper that would download the cache from the master when entering the block and when the block completed, save the specified paths back to the master (ideally in an rsync style way with minimal data movement).  There would also be a maximum cache size so that when the cache grew too large, it would be deleted from the master and started fresh on the next run:

node {
  cache ([maxSize="250M", 
     paths=[
        [path="${HOME}/.gradle/cache", 
           excludes=["${HOME}/.gradle/caches/modules-2/modules-2.lock", "${HOME}/.gradle/caches/*/plugin-resolution"]],
        [path="${HOME}/.gradle/wrapper"]
     ]
  ]) {
     sh './gradlew build -s'
  }
}

Anyone aware of anything like this?

Thanks,
Pete
Reply all
Reply to author
Forward
0 new messages