You can use getItemByFullName
to access a job by name:
Jenkins.instance.getItemByFullName('folder_name/job_name')
. It may require an approval to use it in a Jenkinsfile.
This also opens up more possibilities by retrieving build statusses:
def buildName = Jenkins.instance.getItemByFullName('folder_name/job_name')
echo "Last success: ${buildName.getLastSuccessfulBuild()}"
echo "All builds: ${buildName.getBuilds().collect{ it.getNumber()}}"
echo "Last build: ${buildName.getLastBuild()}"
echo "Is building: ${job.isBuilding()}"
BUT, all of these may require an approval when using it via a Jenkinsfile.
Output for example:
[Pipeline] echo
Last success: folder/job_name #761
[Pipeline] echo
All builds: [767, 766, 765, 764, 763, 762, 761, 760]
[Pipeline] echo
Last build: folder/job_name #767
[Pipeline] echo
Is building: true