Detect Matrix Project

25 views
Skip to first unread message

Nikhil Bhoski

unread,
Oct 10, 2018, 1:49:01 AM10/10/18
to Jenkins Developers

HI all ,

I want to detect if the the project  is of Matrix type or not in my descriptor class so that i could include a jelly  element or could send just include warning message. I tried like belwo which does not work as i dont find MatrixProject class in the jar . Please suggest how could i detect Matrix project in my descriptor and possibly include a warring message in my plugin build step window only for Matrix builds.

i tried below but i dont find MatrixProject class in my jar. 

public boolean isMatrixProject(AbstractProject<?,?> it) {
  return it instanceof MatrixProject;
}

then in jelly you just do

<j:if test="${descriptor.isMatrixProject(it)}">
  ...
</j:if>  

Ullrich Hafner

unread,
Oct 10, 2018, 4:02:53 AM10/10/18
to Jenkins Developers
In which descriptor? And in which jelly file? Maybe you add some more context what you are trying to achieve.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/7fa1e0a5-68a2-4f06-a596-23043061a690%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oliver Gondža

unread,
Oct 10, 2018, 4:45:40 AM10/10/18
to jenkin...@googlegroups.com
Avoid referring to the matrix-plugin's symbols. Compare the class name
instead:

https://github.com/jenkinsci/junit-realtime-test-reporter-plugin/blob/561b341c94890393fe494f63c5c2becaa251ceae/src/main/java/org/jenkinsci/plugins/junitrealtimetestreporter/RealtimeTestResultAction.java#L95
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com
> <mailto:jenkinsci-de...@googlegroups.com>.
> <https://groups.google.com/d/msgid/jenkinsci-dev/7fa1e0a5-68a2-4f06-a596-23043061a690%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
oliver

Nikhil Bhoski

unread,
Oct 10, 2018, 5:02:16 AM10/10/18
to Jenkins Developers
I have static class of BuildStepDescriptor . I want to warn user with specific message ,  if he/she uses the plugin with Matrix build .

so , I want to detect the project type when BuildStepDescriptor loads and send the warrning message or include simple text in jelly file if its Matrix project 

Nikhil Bhoski

unread,
Oct 10, 2018, 5:10:59 AM10/10/18
to Jenkins Developers
Thanks Oliver,

my issue is i am not able to import import hudson.matrix.MatrixBuild; i am not sure why ?

On Wednesday, 10 October 2018 14:15:40 UTC+5:30, ogondza wrote:
Avoid referring to the matrix-plugin's symbols. Compare the class name
instead:

https://github.com/jenkinsci/junit-realtime-test-reporter-plugin/blob/561b341c94890393fe494f63c5c2becaa251ceae/src/main/java/org/jenkinsci/plugins/junitrealtimetestreporter/RealtimeTestResultAction.java#L95

On 10/10/2018 07.49, Nikhil Bhoski wrote:
>
> HI all ,
>
> I want to detect if the the project  is of Matrix type or not in my
> descriptor class so that i could include a jelly  element or could send
> just include warning message. I tried like belwo which does not work as
> i dont find MatrixProject class in the jar . Please suggest how could i
> detect Matrix project in my descriptor and possibly include a warring
> message in my plugin build step window only for Matrix builds.
>
> i tried below but i dont find MatrixProject class in my jar.
>
> public boolean isMatrixProject(AbstractProject<?,?> it) {
>    return it instanceof MatrixProject;
> }
>
> then in jelly you just do
>
> <j:if test="${descriptor.isMatrixProject(it)}">
>    ...
> </j:if>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com

Ullrich Hafner

unread,
Oct 10, 2018, 5:15:07 AM10/10/18
to Jenkins Developers
Is a  BuildStep visible in a MatrixProject? Did you try that? I thought a BuildStep is only visible in Pipelines.

signature.asc

Ullrich Hafner

unread,
Oct 10, 2018, 5:17:24 AM10/10/18
to Jenkins Developers
In order to get the import resolved you need to add a dependency to matrix project. Since you don’t support matrix projects this makes no sense just for the error message;-) So better follow Oliver’s approach. 
(I think you still don’t need the warning at all since a step is not visible in a Matrix project).

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/85c0f0ef-5605-41ea-9da5-d4304a1d1322%40googlegroups.com.
signature.asc

Nikhil Bhoski

unread,
Oct 10, 2018, 5:24:18 AM10/10/18
to Jenkins Developers
Thanks Ullrich , I will try Olivers approach . I could see by Build step in Matrix project . 
Thanks Oliver,

Ullrich Hafner

unread,
Oct 10, 2018, 6:27:18 AM10/10/18
to Jenkins Developers
Hmm, which base class are you extending in your step? Are you implementing SimpleBuildStep as well?

signature.asc

Nikhil Bhoski

unread,
Oct 10, 2018, 7:26:30 AM10/10/18
to Jenkins Developers
Yes , thats right i am extending Builder & implementing SimpleBuildStep . 

I tried Oliver's solution however the static method within my desriptor which extends BuildStepDescriptor is not seem to returning any class name I wrote below method in my descriptor class . am I missing something here ?

public static String isMatrix(AbstractBuild<?, ?> build){
   return build.getClass().getName();
}

I am accessing the string value in my config.jelly  like below 

<j:if test="${descriptor.isMatrix(build)}">
  ...
</j:if> 

Oliver Gondža

unread,
Oct 10, 2018, 7:36:48 AM10/10/18
to jenkin...@googlegroups.com
It is strange it does not return anything. Though I am unsure what
happens when you use boolean as a jelly test condition. This is what I
had in mind (untested):

public boolean isMatrix(AbstractBuild<?, ?> build){
return "hudson.matrix.MatrixBuild".equals(build.getClass().getName());
}

On 10/10/2018 13.26, Nikhil Bhoski wrote:
> Yes , thats right i am extending Builder & implementing SimpleBuildStep .
>
> I tried Oliver's solution however the static method within my desriptor
> which extends BuildStepDescriptor is not seem to returning any class
> name I wrote below method in my descriptor class . am I missing
> something here ?
>
> public static String isMatrix(AbstractBuild<?, ?> build){
>    return build.getClass().getName();
> }
>
> I am accessing the string value in my config.jelly  like below
>
> <j:if test="${descriptor.isMatrix(build)}">
>   ...
> </j:if>
>
> On Wednesday, 10 October 2018 15:57:18 UTC+5:30, Ullrich Hafner wrote:
>
> Hmm, which base class are you extending in your step? Are you
> implementing SimpleBuildStep as well?
>
>> Am 10.10.2018 um 11:24 schrieb Nikhil Bhoski <nikhil...@gmail.com
>> <javascript:>>:
>>
>> Thanks Ullrich , I will try Olivers approach . I could see by
>> Build step in Matrix project .
>>
>> On Wednesday, 10 October 2018 14:47:24 UTC+5:30, Ullrich Hafner wrote:
>>
>> In order to get the import resolved you need to add a
>> dependency to matrix project. Since you don’t support matrix
>> projects this makes no sense just for the error message;-) So
>> better follow Oliver’s approach.
>> (I think you still don’t need the warning at all since a step
>> is not visible in a Matrix project).
>>
>>> Am 10.10.2018 um 11:10 schrieb Nikhil Bhoski
>>> <nikhil...@gmail.com>:
>>>
>>> Thanks Oliver,
>>>
>>> my issue is i am not able to import
>>> importhudson.matrix.MatrixBuild; i am not sure why ?
>>> <http://googlegroups.com/>
>>> > <mailto:jenkinsci-de...@googlegroups.com>.
>>> <https://groups.google.com/d/msgid/jenkinsci-dev/7fa1e0a5-68a2-4f06-a596-23043061a690%40googlegroups.com?utm_medium=email&utm_source=footer
>>> <https://groups.google.com/d/optout>.
>>>
>>>
>>> --
>>> oliver
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the
>>> Google Groups "Jenkins Developers" group.
>>> To unsubscribe from this group and stop receiving emails from
>>> it, send an email tojenkinsci-de...@googlegroups.com.
>>> To view this discussion on the web
>>> visithttps://groups.google.com/d/msgid/jenkinsci-dev/85c0f0ef-5605-41ea-9da5-d4304a1d1322%40googlegroups.com
>>> <https://groups.google.com/d/msgid/jenkinsci-dev/85c0f0ef-5605-41ea-9da5-d4304a1d1322%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>> For more options, visithttps://groups.google.com/d/optout
>>> <https://groups.google.com/d/optout>.
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Jenkins Developers" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to jenkinsci-de...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jenkinsci-dev/63d22d0f-e21f-458f-a586-72cf47a400bb%40googlegroups.com
>> <https://groups.google.com/d/msgid/jenkinsci-dev/63d22d0f-e21f-458f-a586-72cf47a400bb%40googlegroups.com?utm_medium=email&utm_source=footer>.
>> For more options, visit https://groups.google.com/d/optout
>> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com
> <mailto:jenkinsci-de...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com?utm_medium=email&utm_source=footer>.

Nikhil Bhoski

unread,
Oct 10, 2018, 7:53:28 AM10/10/18
to Jenkins Developers
No Luck !

i used the same method as you suggested and then added below in config.jelly . When i created multiconfig project in jenkins it does not include Matrix text box entry . 

<j:if test="${descriptor.isMatrix(build)}">
       <f:entry title="MatrixBuild" field="Matrix">
        <f:textbox/>
  </f:entry> 
 </j:if> 
>>>             > <mailto:jenkinsci-dev+unsub...@googlegroups.com>.

Oliver Gondža

unread,
Oct 10, 2018, 8:27:09 AM10/10/18
to jenkin...@googlegroups.com
The next investigation steps are to see what
`${descriptor.isMatrix(build)}` alone prints in jelly, whether the
(correct) method is invoked and if yes, what is the value of
`build.getClass()`.

On 10/10/2018 13.53, Nikhil Bhoski wrote:
> No Luck !
>
> i used the same method as you suggested and then added below in
> config.jelly . When i created multiconfig project in jenkins it does not
> include Matrix text box entry .
>
> *<j:if test="${descriptor.isMatrix(build)}">*
> *       <f:entry title="MatrixBuild" field="Matrix">*
> *        <f:textbox/>*
> *  </f:entry> *
> * </j:if> *
> <mailto:jenkinsci-de...@googlegroups.com <javascript:>>.
> >>>             > To view this discussion on the web visit
> >>>
> >https://groups.google.com/d/msgid/jenkinsci-dev/7fa1e0a5-68a2-4f06-a596-23043061a690%40googlegroups.com <https://groups.google.com/d/msgid/jenkinsci-dev/7fa1e0a5-68a2-4f06-a596-23043061a690%40googlegroups.com>
> <http://groups.google.com/d/optout>
> >>>             <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >>>
> >>>
> >>>             --
> >>>             oliver
> >>>
> >>>
> >>>         --
> >>>         You received this message because you are subscribed to
> the
> >>>         Google Groups "Jenkins Developers" group.
> >>>         To unsubscribe from this group and stop receiving
> emails from
> >>>         it, send an email tojenkinsci-de...@googlegroups.com.
> >>>         To view this discussion on the web
> >>>
> visithttps://groups.google.com/d/msgid/jenkinsci-dev/85c0f0ef-5605-41ea-9da5-d4304a1d1322%40googlegroups.com
> <http://groups.google.com/d/msgid/jenkinsci-dev/85c0f0ef-5605-41ea-9da5-d4304a1d1322%40googlegroups.com>
>
> >>>
> <https://groups.google.com/d/msgid/jenkinsci-dev/85c0f0ef-5605-41ea-9da5-d4304a1d1322%40googlegroups.com?utm_medium=email&utm_source=footer
> <http://groups.google.com/d/optout>
> >>>         <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >>
> >>
> >>     --
> >>     You received this message because you are subscribed to the
> Google
> >>     Groups "Jenkins Developers" group.
> >>     To unsubscribe from this group and stop receiving emails
> from it,
> >>     send an email to jenkinsci-de...@googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-dev/63d22d0f-e21f-458f-a586-72cf47a400bb%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/jenkinsci-dev/63d22d0f-e21f-458f-a586-72cf47a400bb%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> >>     For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> >>     <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Jenkins Developers" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to jenkinsci-de...@googlegroups.com <javascript:>
> > <mailto:jenkinsci-de...@googlegroups.com <javascript:>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com>
>
> >
> <https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> oliver
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com
> <mailto:jenkinsci-de...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/954678be-60d5-4896-a576-232668ec572a%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-dev/954678be-60d5-4896-a576-232668ec572a%40googlegroups.com?utm_medium=email&utm_source=footer>.

Nikhil Bhoski

unread,
Oct 10, 2018, 8:38:37 AM10/10/18
to Jenkins Developers
"${descriptor.isMatrix(build)}" prints nothing except for two quotes . 
>     <mailto:jenkinsci-dev+unsub...@googlegroups.com <javascript:>>.
>      > <mailto:jenkinsci-dev+unsub...@googlegroups.com <javascript:>>.
>      > To view this discussion on the web visit
>      >
>     https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com
>     <https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com>
>
>      >
>     <https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/jenkinsci-dev/02027d55-ab93-412e-a804-7c8c129061b7%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>      > For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>.
>
>
>     --
>     oliver
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com

Ullrich Hafner

unread,
Oct 10, 2018, 8:44:58 AM10/10/18
to jenkin...@googlegroups.com
I am still wondering why you implement SinmpleBuildStep. This is for Matrix and Freestyle steps so that they are usable in pipelines. But as far as I understand you are supporting only pipelines?

--
Ulli - Typed with big thumbs on small phone
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1aee573f-d462-a11e-95ab-a13e1fd8e6fa%40gmail.com.

Nikhil Bhoski

unread,
Oct 10, 2018, 8:57:07 AM10/10/18
to Jenkins Developers
may be i am not understanding this correctly , but i have plugin with proper UI elements which will be invoked through build step for all project types including freestyle/Matrix etc . i have intention of supporting it to pipeline as well but its in future . currently my intention is not to support pipeline . does that make any sense ? 
>>    <mailto:jenkinsci-dev+unsub...@googlegroups.com <javascript:>>.
>>     > <mailto:jenkinsci-dev+unsub...@googlegroups.com <javascript:>>.
>> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com <mailto:jenkinsci-dev+unsub...@googlegroups.com>.

Jesse Glick

unread,
Oct 10, 2018, 10:25:31 AM10/10/18
to Jenkins Dev
On Wed, Oct 10, 2018 at 8:57 AM Nikhil Bhoski <nikhil...@gmail.com> wrote:
> i have plugin with proper UI elements which will be invoked through build step for all project types including freestyle/Matrix etc . i have intention of supporting it to pipeline as well but its in future . currently my intention is not to support pipeline

Are you overriding

https://javadoc.jenkins.io/hudson/tasks/BuildStepDescriptor.html#isApplicable-java.lang.Class-

? (This is not used by Pipeline, but you can effectively decline to
support Pipeline merely by not implementing `SimpleBuildStep`.)

Nikhil Bhoski

unread,
Oct 11, 2018, 12:38:11 AM10/11/18
to Jenkins Developers
Yes , that's correct my descriptor  is  extending BuildStepDescriptor<Builder>  is that the reason why i am not getting descriptor.getMatrix() is not returning any values in jelly ? 

Ullrich Hafner

unread,
Oct 11, 2018, 5:54:52 AM10/11/18
to Jenkins Developers
If there is an empty String for a boolean then your method has not been invoked. Did you try to set a break point and see if the method is invoked? It is still unclear which jelly file you are modifying?

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
signature.asc

Stephen Connolly

unread,
Oct 15, 2018, 3:00:34 AM10/15/18
to jenkin...@googlegroups.com
In the config pages, there will not be a ‘build’ context variable.

What you want is to either check ‘it.descriptor’ as being the matrix project descriptor or check ‘it’ as being the matrix project class.

But don’t even go there, in your descriptor override ‘isApplicable’ to return false for matrix project (compare by classname) and you won’t even need a warning because it will never appear in the list of options in the first place. 

HTH

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

Nikhil Bhoski

unread,
Oct 18, 2018, 6:11:02 AM10/18/18
to Jenkins Developers
Thanks Stephen , thi sworks with only descriptor however is there any way that i could pass {descriptor} value as parameter to my instance class methods 

eg: <j:test  var= "${it.getVal('descriptor')}"> 

Note that i want to send it as a string to chek the descriptor type . 

Thanks 
Reply all
Reply to author
Forward
0 new messages