Is there an alternative to setting up the whole project workspace in a Jenkinsfile I have a ROS project for which I'm looking to use Jenkins to set up a CI system.

The project has a large number of dependencies which take a long time to build (they can't be installed on the build executor machines), so we typically build them once, then let Catkin (ROS's build system, based on CMake) use the cached artifacts on subsequent builds.

The Jenkins setup we currently have does this:


Clone repository at commit
Create an empty Catkin workspace
Clone and setup all our dependencies
Build everything together
Run tests


Due to building all our dependencies, this takes several hours.

What I'd like to do is this:


Clone repository at commit
Move it into an already built Catkin workspace containing all dependencies
Build just our project
Run tests


I was thinking of setting up a Docker container with all the dependencies ready to go, and then just running the build in that. Is that a typically recommended approach?
Using Docker with Jenkins in a situation like this is a great way to 


Keep Jenkins worker slave nodes clean (so you don't have to build or install anything on them)
Have all dependencies and environment in an easily manageable artifact (in this case, a docker image is the snapshot of the exact OS, filesystem, env and dependencies) 
Vendor / keep copies of dependencies at a certain point in time (Example: You don't want to update at the same rate as the dependency)


If you have some kind of artifact management system (Example: Nexus) you can store your docker images in the artifact management system, and then pull them into Jenkins, and create a running container that has your repository in it. From there you can build project run tests inside the docker image. Just be sure you remember to move/copy all test results and built artifacts out of the docker container if you need them or use them later. 

If you need more details or specifics please edit your question and I will edit my answer accordingly.