How can i use @StepContextParameter to pass EnvVars to my Build

42 views
Skip to first unread message

Nikhil Bhoski

unread,
Mar 16, 2020, 7:57:42 AM3/16/20
to Jenkins Developers
Hi,

i have Builder class which extends SimpleBuildStep and i have SimplebuildWrapper class whcih sets the context envVars. now how should i use @StepContextParameter parameter to pass the EnvVars to my simple build step ? ref to any documentation would be really helpful.

Thanks & Regards
Nikhil

Jesse Glick

unread,
Mar 16, 2020, 2:33:38 PM3/16/20
to Jenkins Dev
On Mon, Mar 16, 2020 at 7:57 AM Nikhil Bhoski <nikhil...@gmail.com> wrote:
> i have Builder class which extends SimpleBuildStep and i have SimplebuildWrapper class whcih sets the context envVars. now how should i use @StepContextParameter parameter to pass the EnvVars to my simple build step ?

This question does not make sense as written. `@StepContextParameter`
is a (deprecated!) way to pass a parameter to a Pipeline `Step`.
`SimpleBuildStep` & `SimpleBuildWrapper` are ways to create extensions
which can work in either traditional or Pipeline builds without
Pipeline-specific APIs.

What are you trying to accomplish?

Nikhil Bhoski

unread,
Mar 17, 2020, 2:16:00 AM3/17/20
to Jenkins Developers
Thanks for response Jesse,
Yes i saw that @StepContextParameter  is deprecated . i have basically two builder classes extending SimpleBuildStep which basically invokes our tool through command line. Before that i have Build wrapper class extending SimpleBuildWrapper which makes sure that the tools path is added in 'PATH' variable . 

problem is above works fine when run using freestyle project however when i cosnstruct a pipeline DSL code then builder fails to invoke the tool as my build step in pipeline does not know where my tool is . (even though it is set in my BuildWrapper class). Please help me with this i have been stuck on this issue from quite a time now . not sure what am i doing wrong here , attaching link to my project 


please check 
Build Wrapper Class
UseMatlabVersionBuildWrapper.java which is my build Wrapper class. 

Builder Classes 




pipeline code that i am trying but does not work is as below.

pipeline {
    agent any
    stages{
        stage('Run MATLAB Command') {
            steps 
            {
                Matlab(matlabRootFolder:'C:\\Program Files\\MATLAB\\R2019b')
                {
                        RunMatlabCommand(matlabCommand:'ver;pwd')

                       // is i replace above step with echo bat('cmd.exe /C matlab -batch pwd') then it works
                }
                
            }
                 
        }
    }
}

Jesse Glick

unread,
Mar 17, 2020, 10:36:06 AM3/17/20
to Jenkins Dev
I see, this is just a report of the same problem with `$PATH` then. I
have no idea what the issue is in your plugin. It works in other
plugins. Start by running those and trying to narrow down the
difference between your case which is not working and other cases
which are.

Nikhil Bhoski

unread,
Mar 17, 2020, 12:07:49 PM3/17/20
to Jenkins Developers
Thanks  Jesse  for your help and the response.

Jesse Glick

unread,
Mar 17, 2020, 12:29:13 PM3/17/20
to Jenkins Dev

Nikhil Bhoski

unread,
Mar 18, 2020, 1:28:58 AM3/18/20
to Jenkins Developers
Thanks a Ton Jesse . I shall try this. again thaks alot !

Nikhil Bhoski

unread,
Apr 3, 2020, 4:14:56 AM4/3/20
to Jenkins Developers
Hi Jesse,

I tried above and it I can set the tool in PATH variable through my SimpleBuildWrapper however i can successfully use the PATH only with bat() or sh() step 
the tool is not getting invoked through my Builder class which basically uses a launcher to invoke a script file which invokes the tool from shell . The problem i see is PATH is not available in my builder class. Do you think it could be a bug on Jenkins that PATH variable is not applicable to the Process launched in Builder class even if the Builder class implements the SimpleBuildStep . Also let me know if i could resolve it by writing separate pipeline step instead using  SimpleBuildStep. 

Thanks & Regards
Nikhil

Jesse Glick

unread,
Apr 3, 2020, 5:06:36 PM4/3/20
to Jenkins Dev
On Fri, Apr 3, 2020 at 4:15 AM Nikhil Bhoski <nikhil...@gmail.com> wrote:
> I tried above and it I can set the tool in PATH variable through my SimpleBuildWrapper however i can successfully use the PATH only with bat() or sh() step
> … PATH variable is not applicable to the Process launched in Builder class even if the Builder class implements the SimpleBuildStep

Ah yes, JENKINS-29144. There is no API for the `SimpleBuildStep` to
retrieve the contextual `$PATH`. You can write a Pipeline-specific
`Step` which will work in that case. (The `SimpleBuildWrapper` is
fine.)
Reply all
Reply to author
Forward
0 new messages