[workflow-plugin] Sample script for deleting a workflow workspace?

608 views
Skip to first unread message

Craig Rodrigues

unread,
Sep 10, 2015, 2:59:06 PM9/10/15
to jenkins...@googlegroups.com
Hi,

James Nord recently fixed:
"add a cross platform step that will delete all files in the current directory."
 https://issues.jenkins-ci.org/browse/JENKINS-30346

This does not address:

'workflow plugin: no opton to "Wipe Out Current Workspace"'
https://issues.jenkins-ci.org/browse/JENKINS-28382

However, it is a step in the right direction.

Can I use a parameterized build, along with this new change to workflow-plugin to do the following:

(1) I have a workflow.
(2) With the workflow, I have a build parameter, "do_clean" which by default is set to 0.
(3) If "do_clean" is set to 1, then logic in the workflow will be triggered which cleans out the files,
otherwise if "do_clean" is set to 0, then no cleaning occurs.

If this is possible, could someone post a code snippet of a workflow which does this?

Thanks.

--
Craig

Oleg Nenashev

unread,
Sep 28, 2015, 3:59:01 PM9/28/15
to Jenkins Users, rod...@freebsd.org
If you specify a boolean parameter, the Workflow code would be...

node {
   if (clean_dir) {
       deleteDir()
   }
   ...
   // Further logic
}

четверг, 10 сентября 2015 г., 21:59:06 UTC+3 пользователь Craig Rodrigues написал:

Craig Rodrigues

unread,
Sep 29, 2015, 4:51:09 PM9/29/15
to Oleg Nenashev, Jenkins Users
It might be worth it to take the deleteDir() example from DeleteDirStepTest.java and put it in help.html,
since the help.html is rather sparse.

I would recommend as new functions are added to the workflow plugin which can
be called from a workflow script, that they be
documented in TUTORIAL.md as well.

--
Craig

Oleg Nenashev

unread,
Oct 1, 2015, 4:02:24 AM10/1/15
to Craig Rodrigues, Jenkins Users
Hi Craig,

I noticed that the deleteDir() feature has not been released yet. It should appear in workflow-1.11. Can be temporarily replaced by a script invocation via "sh".

Thanks a lot for your feedback regarding the documentation. As you probably see, it's being reworked now. I'll forward your proposal to Esther  , who works on the docs now. BTW, also feel free to contribute :)

Best regards,
Oleg Nenashev

Jesse Glick

unread,
Oct 1, 2015, 9:07:41 AM10/1/15
to Jenkins Users, o.v.ne...@gmail.com, rod...@freebsd.org
On Tuesday, September 29, 2015 at 4:51:09 PM UTC-4, Craig Rodrigues wrote:
It might be worth it to take the deleteDir() example from DeleteDirStepTest.java and put it in help.html

I am not seeing anything in the test not covered by the help; maybe I am missing something?

I would recommend as new functions are added to the workflow plugin which can
be called from a workflow script, that they be
documented in TUTORIAL.md as well.

The original intent (since corrupted somewhat) of that file was to be an actual tutorial you could follow in document order, trying each revision for yourself. Forcing it to include every possible step could just become overwhelming. There are other formats which work better for listing idioms.

On Mon, Sep 28, 2015 at 12:59 PM, Oleg Nenashev <o.v.ne...@gmail.com> wrote:
If you specify a boolean parameter, the Workflow code would be...

node {
   if (clean_dir) {

Not quite; as noted in JENKINS-27295 you will actually get `"true"` or `"false"` not `true` or `false`, so for now you would need to use something like

if (Boolean.valueOf(clean_dir)) {

or

if (clean_dir == 'true') {

By the way this kind of question is better suited to Stack Overflow.

Craig Rodrigues

unread,
Oct 1, 2015, 6:42:19 PM10/1/15
to Oleg Nenashev, Jesse Glick, Jenkins Users
On Thu, Oct 1, 2015 at 1:02 AM, Oleg Nenashev <o.v.ne...@gmail.com> wrote:
Thanks a lot for your feedback regarding the documentation. As you probably see, it's being reworked now. I'll forward your proposal to Esther  , who works on the docs now. BTW, also feel free to contribute :)

Since the stuff I asked about is not yet in a released version of workflow-plugin,
I'm fine, since I realize things are in motion. :)

For now, if I have to look inside the tests to figure out the different functions in workflow,
that is OK, but that won't be good later on.

workflow is different from most plugins, since it is being very heavily
promoted by Jenkins core developers.  Since workflow is almost a small domain-specific language,
enhancing the docs as new functions are added becomes very important.  It is great that you
have a documentation writer working with the workflow-plugin developers!



On Thu, Oct 1, 2015 at 6:07 AM, Jesse Glick <jgl...@cloudbees.com> wrote:

I am not seeing anything in the test not covered by the help; maybe I am missing something?


The wording in the help is technically correct, but i found the code example
in the test is more illustrative and easier to understand than the help text.
Since things are early stage and moving with workflow, having to look at the
code to understand things is OK, but in future, having good docs is important.

 

I would recommend as new functions are added to the workflow plugin which can
be called from a workflow script, that they be
documented in TUTORIAL.md as well.

The original intent (since corrupted somewhat) of that file was to be an actual tutorial you could follow in document order, trying each revision for yourself. Forcing it to include every possible step could just become overwhelming. There are other formats which work better for listing idioms.

Oh OK.  Maybe workflow needs both?  a TUTORIAL.md which can be followed,
and a comprehensive doc which lists all the functions?  I don't know the best approach,
but since you have a doc writer helping, maybe they can suggest a good approach.

--
Craig
Reply all
Reply to author
Forward
0 new messages