In today’s post, I will describe how to add permission to copy artifacts in Jenkins.
In one of my projects, there was an interesting issue related to permissions to copy artifacts between jobs in Jenkins. While working on migrating jobs from one system to another in the new Jenkins, the following error appeared:
ERROR: Unable to find project for artifact copy: my first project
This may be due to incorrect project name or permission settings; see help for project name in job configuration.
The error was related to the Copy Artifact plugin, whose purpose is to allow artifacts to be copied between jobs. With version 1.44, this plugin runs by default in production mode, which means that copy permissions are set much more restrictively.
In my case, migrating jobs between systems also triggered a new version of the plugin that blocked all artifact copy attempts by default.
How to solve this problem?
This problem can be solved in three ways:
- add information about which task can copy artifacts
When configuring jobs, we can add information about which task can copy artifacts:
1. on the job setup page
On the job configuration page there is an option Permission to Copy Artifact. When this option is checked, we can specify tasks that will have permission to copy artifacts. When adding a name, Jenkins will try to find a suitable name and suggest one.
Importantly, we can specify multiple tasks separated by commas. We can also use the * (asterisk) sign to provide a schema for the task name.
2. in pipeline definition (declarative mode)
copyArtifactPermission('Copy artifacts project,...');
3. in pipeline definition (script mode)
copyArtifactPermission('Copy artifacts project,...'),
- Use the Authorize Project plugin
The Authorize Project plugin allows you to run a task as a specific user. After installing this add-on, you can add information that the task is run as a user with read permissions to artifacts.
- Migration mode (not recommended)
Copy Artifacts plugin enables a migration mode that allows you to disable permission checking. This mode is designed to migrate from an old version of the add-on to a new one and should not be used in a production environment longer than needed.