Re: Request to on how get "workspace" location from Run object - for workflow compatibilty

181 views
Skip to first unread message

Mads Nielsen

unread,
Aug 28, 2015, 2:37:34 AM8/28/15
to jenkin...@googlegroups.com
You can get the Workspace from the run object by doing run.getExecutor().getCurrentWorkspace(). 

Since you're a build wrapper you have a footprint just after checkout of workspace....so you should have a workspace at that point in the run object.


____________________________________________________________
Mads Nielsen
Consultant
m...@praqma.net
+45 50 98 18 09
Skype: inkspot
Praqma
www.praqma.com
Allerød Stationsvej 4
DK-3450 Allerød
+45 36 77 27 62

On Fri, Aug 28, 2015 at 6:20 AM, Vinodhini Vijay <vinodhi...@gmail.com> wrote:

Hello All,

I would like to get the workspace of the Run object. To make workflow compatible, my custom build wrapper class extends SimpleBuildWrapper.

I  had overridden the method :

public void setUp(Context context, Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment)
            throws IOException, InterruptedException

But, how to get the workspace directory location from the Run object? (As I have to read some file within workspace)

I tried to typecast to AbstractBuild, but during build I got ClassCastException

java.lang.ClassCastException: org.jenkinsci.plugins.workflow.job.WorkflowRun cannot be cast to hudson.model.AbstractBuild

My Workflow code was:

node{
wrap([$class: 'MyCustomBuildWrapper']) {
print ('Hello')
}
}

Also, after workflow build is completed, will the workspace gets deleted? (As, I couldn't find the workspace folder in my Jenkins home (Also couldn't find Workspace Icon/link in Jenkins GUI) after the build completes)

Or will the workspace gets created only after SCM checkout?

Thanks

--
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/eccdf524-e7a2-4eb2-bba7-839b9a062cc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Beck

unread,
Aug 28, 2015, 4:06:05 AM8/28/15
to jenkin...@googlegroups.com

On 28.08.2015, at 06:20, Vinodhini Vijay <vinodhi...@gmail.com> wrote:

> I had overridden the method :
>
> public void setUp(Context context, Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment)
> throws IOException, InterruptedException
>
> But, how to get the workspace directory location from the Run object? (As I have to read some file within workspace)

The point of SimpleBuildWrapper and similar other interfaces is that it tells you e.g. the relevant workspace as a parameter. This way your Workflow job/run can have any number of workspaces in parallel.

---

On 28.08.2015, at 08:37, Mads Nielsen <m...@praqma.net> wrote:

> You can get the Workspace from the run object by doing run.getExecutor().getCurrentWorkspace().

From Javadoc of Executor#getCurrentWorkspace():

> If current executable is AbstractBuild, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.

So that won't work for Workflow, which isn't based on AbstractBuild.

Robert Sandell

unread,
Aug 28, 2015, 4:36:57 AM8/28/15
to jenkin...@googlegroups.com
I.e. you have it right in front of you :)


public void setUp(Context context, Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment)
--
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.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Mads Nielsen

unread,
Aug 28, 2015, 4:52:45 AM8/28/15
to jenkin...@googlegroups.com
Haha..just noticed that too...the case of not being able to see the forrest because of all the trees! :)

____________________________________________________________
Mads Nielsen
Consultant
m...@praqma.net
+45 50 98 18 09
Skype: inkspot
Praqma
www.praqma.com
Allerød Stationsvej 4
DK-3450 Allerød
+45 36 77 27 62

Vinodhini Vijay

unread,
Aug 28, 2015, 5:34:49 AM8/28/15
to Jenkins Developers, m...@beckweb.net

Thank you all!! :) Is it valid to use the below to get the AbstractProject  or Project  or WorkFlowJob?

SubTask currentExecutable = run.getExecutor().getCurrentExecutable().getParent();

Thanks!

Robert Sandell

unread,
Aug 28, 2015, 5:43:33 AM8/28/15
to jenkin...@googlegroups.com
use run.getParent() instead.

/B

--
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.

Vinodhini Vijay

unread,
Aug 28, 2015, 6:11:56 AM8/28/15
to Jenkins Developers
Thank you! If ,config.jelly is not present for CustomBuildWrapper (extends SimpleBuildWrapper), the below exception is thrown for Workflow job . No exception if used via FreeStyleProject

Aug 28, 2015 3:36:26 PM hudson.widgets.RenderOnDemandClosure$1 generateResponse
WARNING: Failed to evaluate the template closure
org.apache.commons.jelly.JellyTagException: jar:file:.../target/work/webapp/WEB-INF/lib/jenkins-core-1.609.2.jar!/lib/form/dropdownDescriptorSelector.jelly:60:78: <st:include> No page found 'config.jelly' for class my.CustomBuildWrapper$DescriptorImpl
    at org.kohsuke.stapler.jelly.IncludeTag.doTag(IncludeTag.java:124)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:269)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.kohsuke.stapler.jelly.CallTagLibScript$1.run(CallTagLibScript.java:99)
    at org.apache.commons.jelly.tags.define.InvokeBodyTag.doTag(InvokeBodyTag.java:91)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:269)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:161)
    at org.apache.commons.jelly.tags.core.OtherwiseTag.doTag(OtherwiseTag.java:41

CustomBuildWrapper doesn't have any GUI apart from the default one(one checkbox) provided by SimpleBuildWrapper (i guess it is from SimpleBuildWrapper).

The above exception occurs when Snippet Generator is used to get the groovy code. Any solutions?

Thank you!

Jesse Glick

unread,
Aug 28, 2015, 7:23:57 AM8/28/15
to Jenkins Dev
On Fri, Aug 28, 2015 at 6:11 AM, Vinodhini Vijay
<vinodhi...@gmail.com> wrote:
> CustomBuildWrapper doesn't have any GUI

Does not matter, it should still offer a `config.jelly`:

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"/>
Reply all
Reply to author
Forward
0 new messages