-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins 2.303.3
Folders Plugin 6.17
Per my reading online, Jenkins job/project names are by design case insensitive. However, I ran into a case where the case seems to matter. Please see the details below. I have changed the names to protect client's internal details in the code below.
I have a folder named ABC-DevOps-Pipeline-Templates and a pipeline in that folder named Pipeline-Name. Please note that casing.
I'm running this in Script Console for this illustration.
Jenkins j = Jenkins.getInstanceOrNull() println j.getItemByFullName("ABC-DevOps-Pipeline-Templates/Pipeline-Name") println j.getItemByFullName("ABC-DevOps-pipeline-templates/Pipeline-Name") println j.getItemByFullName("ABC-DevOps-Pipeline-Templates/pipeline-Name")
Here are the results:
org.jenkinsci.plugins.workflow.job.WorkflowJob@4cfb20a0[ABC-DevOps-Pipeline-Templates/Pipeline-Name]
org.jenkinsci.plugins.workflow.job.WorkflowJob@4cfb20a0[ABC-DevOps-Pipeline-Templates/Pipeline-Name]
null
As you can see in the first two lines, the case of the folder name doesn't seem to matter which is correct. Notice the p and the t in the Pipeline-Template in the second line. In the third line, somehow the case of the pipeline seem to matter - note the p vs P in the pipeline name.
The Jenkins code that is running the getItemByFullName is https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/Jenkins.java#L3064. I tried to see where exactly it is failing by running the below code which is basically the lines from that method.
void test(String folderName, String pipelineName) { Jenkins j = Jenkins.getInstanceOrNull(); println "get by full name: " + j.getItemByFullName(folderName + "/" + pipelineName) println "get by full name with type: " + j.getItemByFullName(folderName + "/" + pipelineName, org.jenkinsci.plugins.workflow.job.WorkflowJob.class) println "is folder isntance of ItemGroup: " + (j.getItem(folderName) instanceof ItemGroup) println "folder have permission: " + j.getItem(folderName).hasPermission(Item.READ) ItemGroup parent = (ItemGroup) j.getItem(folderName) println "parent folder: " + parent println "getItem on folder: " + parent.getItem(pipelineName) }
Then I ran this
test("ABC-DevOps-Pipeline-Templates", "Pipeline-Name")
output as expected
get by full name: org.jenkinsci.plugins.workflow.job.WorkflowJob@4cfb20a0[ABC-DevOps-Pipeline-Templates/Pipeline-Name] get by full name with type: org.jenkinsci.plugins.workflow.job.WorkflowJob@4cfb20a0[ABC-DevOps-Pipeline-Templates/Pipeline-Name] is folder isntance of ItemGroup: true folder have permission: true parent folder: com.cloudbees.hudson.plugins.folder.Folder@38b8f698[ABC-DevOps-Pipeline-Templates] getItem on folder: org.jenkinsci.plugins.workflow.job.WorkflowJob@4cfb20a0[ABC-DevOps-Pipeline-Templates/Pipeline-Name]
I get the same output no matter what the folder casing is. Even
test("abc-dEvOpS-pIPelINe-Templates", "Pipeline-Name")
returns the same exact output.
When I change the casing of the pipeline name (note the small p in the pipeline name):
test("ABC-DevOps-Pipeline-Templates", "pipeline-Name")
output is not as expected. This output should have been the same as the output above.
get by full name: null get by full name with type: null is folder isntance of ItemGroup: true folder have permission: true parent folder: com.cloudbees.hudson.plugins.folder.Folder@38b8f698[ABC-DevOps-Pipeline-Templates] getItem on folder: null
The issue seems to be in the implementation of the folder plugin (https://github.com/jenkinsci/cloudbees-folder-plugin) specifically somewhere in here https://github.com/jenkinsci/cloudbees-folder-plugin/blob/master/src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java