Pinning a node to a particular workspace in jenkins pipeline?

90 views
Skip to first unread message

Craig Silverstein

unread,
Sep 5, 2017, 3:55:52 PM9/5/17
to Jenkins Users
I have a jenkins pipeline script that does something like this:
```
node('master') { do_stuff(params.FOO); }
prompt "Look good?"
node('master') { do_more_stuff(); }
```

`do_more_stuff()` depends on workspace-changes made by `do_stuff()` (files created, repos synced, etc).

This worked fine when only one job could run at a time, but we recently changed it so you could run two jobs concurrently, and now have a problem that a single job could use different workspaces for `do_stuff` and `do_more_stuff`.  That is, job A could use workspace@1 for do_stuff but workspace@2 for do_more_stuff, if job B was using workspace@1 at the time.  This causes the job to behave badly since the workspace isn't set up properly for `do_more_stuff`.

I could solve this by doing
```
nost('master') {
    do_stuff(...);
    prompt ...
    do_more_stuff(...);
}
```
but I'm trying to free up the executor while waiting for the prompt to be executed (it could be a while).

Are there any other ways to solve this problem?  What are the best practices here?  I feel I must be missing something in how `node` is supposed to be used.

craig

niristotle okram

unread,
Sep 5, 2017, 4:21:27 PM9/5/17
to jenkins...@googlegroups.com
i have ran into this in the past, but we manage to solve this by assigning a workspace for each build. there is a dsl -  ws(). 

Another thing regarding the executor while waiting for user input, use the input(), outside of node{}.






--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0cc87af6-82e8-4e17-9398-1fa93e9a684c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards
nirish okram

Craig Silverstein

unread,
Sep 5, 2017, 4:52:03 PM9/5/17
to Jenkins Users
Thanks for that link -- that was very helpful!

Here's a snippet from it:
```

EDIT: As pointed out by @amuniz, you have to stash/unstash the contents of the workspace, as different nodes respectively workspace directories might be allocated for the two node steps.

```
so that's another approach to take.

craig


On Tuesday, September 5, 2017 at 1:21:27 PM UTC-7, ok999 wrote:
i have ran into this in the past, but we manage to solve this by assigning a workspace for each build. there is a dsl -  ws(). 

Another thing regarding the executor while waiting for user input, use the input(), outside of node{}.





On Tue, Sep 5, 2017 at 2:14 PM, Craig Silverstein <csil...@khanacademy.org> wrote:
I have a jenkins pipeline script that does something like this:
```
node('master') { do_stuff(params.FOO); }
prompt "Look good?"
node('master') { do_more_stuff(); }
```

`do_more_stuff()` depends on workspace-changes made by `do_stuff()` (files created, repos synced, etc).

This worked fine when only one job could run at a time, but we recently changed it so you could run two jobs concurrently, and now have a problem that a single job could use different workspaces for `do_stuff` and `do_more_stuff`.  That is, job A could use workspace@1 for do_stuff but workspace@2 for do_more_stuff, if job B was using workspace@1 at the time.  This causes the job to behave badly since the workspace isn't set up properly for `do_more_stuff`.

I could solve this by doing
```
nost('master') {
    do_stuff(...);
    prompt ...
    do_more_stuff(...);
}
```
but I'm trying to free up the executor while waiting for the prompt to be executed (it could be a while).

Are there any other ways to solve this problem?  What are the best practices here?  I feel I must be missing something in how `node` is supposed to be used.

craig

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



--
Regards
nirish okram

Martin d'Anjou

unread,
Sep 6, 2017, 5:26:49 PM9/6/17
to Jenkins Users
The External Workspace Manager Plugin can be used to solve this problem.
I use it every day. It saves time as there is no stashing required.

Here is an example of reusing the workspace with two nodes in the same job:

def extWorkspace = exwsAllocate 'diskpool1'
node
('linux') {
    exws
(extWorkspace) { sh 'do stuff' }
}
node
('test') {
  exws
(extWorkspace) { sh 'more stuff' }
}


Two different jobs can also reuse the same workspace, again without stashing, see this example. You will need the run selector plugin for this case.

If you need help to set it up, post your question here, I should be able to help you.

Martin

Craig Silverstein

unread,
Sep 6, 2017, 5:32:09 PM9/6/17
to Jenkins Users
Thanks for the suggestion!  I had thought of using external workspaces originally, but I want each job to have a unique workspace, but to pick an unused workspace when possible (since creating a new workspace is quite expensive in our case).  I didn't relish the idea of having to manage the lists of free and used workspaces myself.  I do like the fact there's no stashing required, though. :-)

craig
Reply all
Reply to author
Forward
0 new messages