'Job Import Plugin doesn’t import folder
I’m currently trying to import jobs from a server running on AWS to a new server running on GCP Kubernetes.
I already set up the Job Import Plugin version 3.4 on the new server.
When I tried to import the jobs it worked when it was only 1 job.
But when I imported a Folder with jobs and folders inside, the Folder is imported with nothing inside.
Old Server: Jenkins version 2.127
New Server: Jenkins version 2.289.2
Any help?
Solution 1:[1]
The plugin appears to provide NO documentation, either in the legacy wiki page, the Plugins page, or the GitHub repo. This answer from @valdeci does a good job of providing usage instructions.
TL;DR : You have to do it in phases; folders, then jobs in each folder. The recurse into folders just does not work well.
ISSUE : Jenkins treats a Folder object as just another Job type, similar to Freestyle Job and Pipeline Job (hence the "New Item" presentation). It's evident the plugin does not handle folders and jobs inside folders intuitively. It also does not provide direct feedback to the user (errors are in the jenkins.log).
CONTEXT : Using Jenkins 1.121.3, plus job-import-plugin-3.3,folders-6.5.1 worked as expected, as long as you picked the folder and the nested jobs at the same time.
There are a number of open issues for the plugin, including:
JENKINS-64121: Jenkins ImportPlugin - Error '/' unsafe character
and 53902 (The folder alone is copied, but not the job present inside the folder). I don't know when the behaviour changed, but is possible however to to import the jobs.
Configuration/ Setup :
The following is verified Jenkins-2.289.3, with job-import-plugin-3.4,folders-6.16.
Assume you installed, configured the job-import plugin (left image), clicked on the Job Import plugin button (or ${JENKINS_URL}/job-import
(right image) ):
You have empty target structure and a source structure:
JobInRoot
AFolder
AFolder/JobInFolder
FAILURE OUTCOME :
If you click Query!, the response will be JobInRoot
and AFolder
Select both and it will import the JobInRoot
AND AFolder
, but not its contents. That's because it just imported the two Job items (Freestyle job item and Folder job item); it does not recursively import the jobs inside the folder.
JobInRoot SUCCESS
AFolder SUCCESS
If you tick [ X ] Search into folders
and click Query! and the response will be all three items. Selecting all three items and Import!, you result in:
JobInRoot SUCCESS
AFolder SUCCESS
JobInFolder FAILED - ‘/’ is an unsafe character
WORKAROUND SOLUTION :
- As shown above, Import the Folder
AFolder
first. - Run Job Import plugin again, but set RemoteFolder to [
job/AFolder
], then Query!. This is to work around the unsafe "/" character issue and the poor plugin handling of folders. You'll now see the nested jobs insideAFolder
. - Set
Copy to folder [ AFolder ]
, selectJobInFolder
, Import!
JobInFolder SUCCESS
and the job is actually in AFolder/JobInFolder
3a. To handle nested folders (eg: L1Folder/L2Folder/L3Folder/jobInFolder3) into nested folders, again iterate, but each level needs the "job/” prefix inserted, ie: RemoteFolder [ job/L1Folder/job/L2Folder/job/L3Folder ...
]. Do not prepend the rooturl, just from the "job/": the qualified itemByFullName-ish.
3b. If you wish to copy nested jobs to the root folder, you must set Copy to folder [ / ]
, or you will get:
JobInFolder FAILED null
There are probably more nuances, but this approach should help migrate most items. Have not tested options [ ] Install required plugins or [ ] Override existing jobs.
Solution 2:[2]
At least on our Cloudbees Jenkins server, the "Remote Folder" needs to be in the format "job/AWS%20Jobs/" with no leading slash, job, a trailing slash, and encoded e.g. spaces are %20. Then hit Query.
Then on the job selection page, you can put them into an existing folder. And because Jenkins is wildly inconsistent, here the folder name should be in the format "AWS Jobs" instead of the above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | JBB |