In many places throughout Jenkins, you can refer to another project/job by name. For example, in a Pipeline Script, you might want to copy artifacts from another project:
copyArtifacts projectName: 'myproject'
That's all you need to do if your target project's name is simply alphanumeric, and is a simple project without subprojects, and has a unique name throughout your entire Jenkins instance. Read on for more complex scenarios…
Differentiating between multiple projects with the same name
If you're using the Folders Plugin and you have multiple projects with the same name but are in different folders, you can differentiate between them using a path, similar to a Unix filesystem path. There are two types of paths:
Absolute paths
Absolute paths begin with a forward slash, and refer to a project by describing the complete path to navigate to the project from the home page of your Jenkins instance. For example, to reference a project in the root of your Jenkins instance:
/myproject
Or, to reference a project in a subfolder:
/myfolder/myproject
Relative paths
Relative paths begin with something other than a forward slash, and refer to another project in relation to the current project. For example, say you have projects with the following absolute paths:
/thatproject
/folder/someproject
/folder/subfolder/myproject
/folder/subfolder/anotherproject
In a Pipeline Script for /folder/subfolder/myproject
, you could refer to /folder/subfolder/anotherproject
using this relative path:
anotherproject
And you could refer to /folder/someproject
using this relative path, where ..
means to look in the parent folder:
../someproject
And you could refer to /thatproject
using this relative path:
../../thatproject
Referencing components inside projects
Some types of projects — such as Maven projects, Matrix projects, and Multibranch projects — have subcomponents. You can refer to these subcomponents as follows:
Maven projects
You can refer to an entire Maven project:
mymavenproject
Or to a group within a Maven project:
mymavenproject/my.group
Or to a particular module:
mymavenproject/my.group$MyModule
Matrix projects
You can refer to all configurations of a Matrix project:
mymatrixproject
Or to a particular configuration, restricted by a axis:
mymatrixproject/someaxis=somevalue
Or restricted by multiple axes:
mymatrixproject/someaxis=somevalue,anotheraxis=anothervalue
Multibranch Pipelines
You can refer to a particular branch:
mymultibranchproject/mybranch
Name encoding
Special characters in paths should be URL-encoded. For example, if your Multibranch Pipeline has a branch with a slash in it (feature/myfeature
), replace the slash with %2F
:
mymultibranchproject/feature%2Fmyfeature
For developers of Jenkins and Jenkins Plugins
See the Jenkins::getItem()
function.