jenkinsci/custom-folder-icon-plugin

Missing symbols for JobDSL

jonesbusy opened this issue · 9 comments

What feature do you want to see added?

Hi,

At the moment I was not able to find any Symbol to configure jobs and folder with custom icon.

Using jobDSL we must use configure block which is a bit painful

folder('my-folder') {
  description('my-folder')
  configure {
    it.remove(it / 'icon')
    it / 'icon'(class: 'jenkins.plugins.foldericon.IoniconFolderIcon', plugin: 'custom-folder-icon') {
      ionicon('bag-sharp')
    }
  }
}

Would be nice to have discoverable Symbol to configure the 'icon' field without relying on the configure block.

For example

folder('my-folder') {
  description('my-folder')
  icon {
     ionicon('bag-sharp')
  }
}

Regards,

Upstream changes

Maybe require some change on the branch-api plugin. I'm not sure

I'd like to implement this, however I have no idea where to start 😕
I feel like the first thing would be an upstream change to https://github.com/jenkinsci/job-dsl-plugin to have the icon configuration available? Maybe @daspilker can help?

Hi,

I think there is not need to change anything on JobDSL plugin.

Dynamic DSL should be used (https://github.com/jenkinsci/job-dsl-plugin/wiki/Dynamic-DSL)

I did some similar change on an other plugin : https://github.com/jenkinsci/github-checks-plugin/pull/289/files

So basically adding the correct Symbol should be enough.

Hope it helps

Taking your example for a build with JobDSL plugin:

folder('my-folder') {
  description('my-folder')
  icon {
     ionicon('bag-sharp')
  }
}

And adding the Symbol to the IoniconFolderIcon.java like in your PR:

@Extension
@Symbol("ionicon")
public static class DescriptorImpl extends FolderIconDescriptor {

Results in

Processing provided DSL script
ERROR: (script, line 2) No signature of method: javaposse.jobdsl.dsl.Folder.icon() is applicable for argument types: (script$_run_closure1$_closure2) values: [script$_run_closure1$_closure2@64f85f0]
Possible solutions: is(java.lang.Object), wait(), any(), find(), grep(), dump()
Finished: FAILURE

What am I missing here?

Hi,

I have the feeling the icon() comes from this plugin cloudbees-folder. Probably the symbol is missing there :

https://github.com/jenkinsci/cloudbees-folder-plugin/blob/daf4ca032c70095bf1476b04ed907f636b65adcf/src/main/java/com/cloudbees/hudson/plugins/folder/FolderIcon.java#L46

You can check on the test instance the job dsl viewer : <your instance>/plugin/job-dsl/api-viewer/index.html

I think is also important to test also with multibranchPipelineJob. For some reason I was not able to even use the configure block (not sure what is happening). Same configure block work for folder, but not multibranchPipelineJob

multibranchPipelineJob('my-multibranch') {
  description('my-multibranch')
  configure {
    it.remove(it / 'icon')
    it / 'icon'(class: 'jenkins.plugins.foldericon.IoniconFolderIcon', plugin: 'custom-folder-icon') {
      ionicon('bag-sharp')
    }
  }
}

I think the last issue I mentionned is related link to : #94

I have the feeling the icon() comes from this plugin cloudbees-folder. Probably the symbol is missing there :

https://github.com/jenkinsci/cloudbees-folder-plugin/blob/daf4ca032c70095bf1476b04ed907f636b65adcf/src/main/java/com/cloudbees/hudson/plugins/folder/FolderIcon.java#L46

I think so, too. I'll check if I can get it to work locally and create PR if required.

Adding @Symbol does not seem to have any effect, the same error remains.

Can anyone of @jenkinsci/job-dsl-plugin-developers give me a pointer were to start?

So I found that it seems to be required to adapt the job-dsl-plugin for this to work. I created jenkinsci/job-dsl-plugin#1258 for that.

If it gets merged, your use case should work OOTB like so:

folder('my-folder') {
  description('my-folder')
  icon {
    ioniconFolderIcon {
      ionicon('bag-sharp')
    } 
  }
}

Fixed once jenkinsci/job-dsl-plugin#1258 is merged. Whenever that will be 🤷🏼