jenkinsci / jobtag-plugin

https://plugins.jenkins.io/jobtag/
Apache License 2.0
4 stars 4 forks source link

Define tags in the Jenkinsfile #15

Closed dmtumilovich closed 2 years ago

dmtumilovich commented 2 years ago

Hello,

Is there any option to define tags inside the Jenkinsfile, rather than in UI?

I tried this (that was suggested by snippet generator):

properties([
        [$class: 'io.jenkins.plugins.jobtag.JobTagPublisher', tags: [[value: 'Tag1'], [value: 'Tag2']]]
])

But it throws the following exception:

java.lang.IllegalArgumentException: java.lang.ClassCastException@5702a059
    at jdk.internal.reflect.GeneratedMethodAccessor40303.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.jenkinsci.plugins.structs.describable.Setter$1.set(Setter.java:33)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:429)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:331)
Caused: java.lang.IllegalArgumentException: Could not instantiate {tags=[{value=Tag1}, {value=Tag2}]} for io.jenkins.plugins.jobtag.JobTagPublisher
...
nistal97 commented 2 years ago

def tags = new HashSet<io.jenkins.plugins.jobtag.JobTag>() tags.add(new io.jenkins.plugins.jobtag.JobTag("tester")) properties([ [$class: 'io.jenkins.plugins.jobtag.JobTagPublisher', tags: tags] ])

even you can specify a color

def tags = new HashSet<io.jenkins.plugins.jobtag.JobTag>() def testertag = new io.jenkins.plugins.jobtag.JobTag("tester1") testertag.setColor("#DEA093") tags.add(testertag) properties([ [$class: 'io.jenkins.plugins.jobtag.JobTagPublisher', tags: tags] ]) @dmtumilovich

dmtumilovich commented 2 years ago

@nistal97 thanks a lot! That helped.