I need to create a new build pipeline that is almost identical to an existing one, but I want to avoid configuring all the build steps, environment variables, and Git triggers from scratch. Is there a "Clone" button I’m missing in the Jenkins UI, or do I have to use a specific plugin or the "New Item" copy feature? Also, if I clone a job, does it automatically copy over the build history and old artifacts, or just the configuration settings?
3 answers
The most straightforward way to clone a job is via the Jenkins Dashboard. Click on 'New Item', enter your new job name, and at the bottom of the page, you will see a field labeled 'Copy from'. Type the name of your existing job there, and Jenkins will autocomplete it. This creates a new job with an identical configuration, including build steps and post-build actions. However, please note that this only copies the configuration (the config.xml file). It does not copy the build history, workspace data, or previous artifacts from the source job. If you need to move those as well, you would need to manually copy the job directory on the Jenkins controller's file system and restart the server.
Does using the 'Copy from' feature also duplicate the specific credentials and API tokens used in the original job, or do those need to be re-selected manually in the new project configuration?
If you find yourself cloning jobs frequently, you should look into the "Job Config History" plugin or start using Jenkins Pipeline (Jenkinsfile). Using code-based pipelines makes "cloning" as simple as copying a text file.
I agree with Linda. I moved our team to Jenkinsfiles stored in Git last year. Now, instead of clicking through the UI to clone jobs, we just point a new 'Multibranch Pipeline' to a new repo branch. It's much more scalable for an SEO specialist's workflow!
Kevin, the 'Copy from' feature duplicates the reference to the credentials (the ID), so as long as the credentials are stored at the Global or Folder level that both jobs can access, they will work immediately. However, if the original job used "Secret Text" or "Passwords" hardcoded directly into the build steps (which isn't best practice), those will be copied exactly as they are. It’s always a good idea to verify the 'Credentials' dropdown in the new job just to ensure the scope hasn't changed.