Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-11285

Ability to run postbuild script on a given node

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      For the postbuild script plugin, would be really nice to have the option to select which node (slaves or master) to run the script on. I have a scenario where the slaves do not have access to certain network areas (but the master does) - wanted to use maven to deploy the artifact but slaves can't 'see' anything on port 80 (I'd use the "copy to master" in conjunction with this plugin to perform the maven deploy), so would be awesome to have this functionality.

        Attachments

          Activity

          Hide
          dheid Daniel Heid added a comment -

          Hey James,

          I cannot reproduce the problem.

          Are you running the Groovy script on the agent or on the master?

          Could you please provide the config.xml or at least an excerpt of it here?

          Show
          dheid Daniel Heid added a comment - Hey James, I cannot reproduce the problem. Are you running the Groovy script on the agent or on the master? Could you please provide the config.xml or at least an excerpt of it here?
          Hide
          jamesco James Coleman added a comment -

          Thanks Daniel, I think it is maybe because I am using an older release of jenkins (Jenkins ver. 2.60.2)
          I upgraded to LTS v2.73.1 and I still had problem with latest PostBuildScript. Downgrade to plugin version 0.18.1 works for me. We will not be able to go past LTS v2.73.1 . . . for a while. If I have time next week I could test with latest jenkins

          config.xml not sure will it help if the problem is version of jenkins core is too old
          the PostBuildScript part of the config is cleared out as expected in GUI if I downgrade from 2.0.0 to 0.18.1
          the PostBuildScript part of the config is updated as expected in GUI if I upgrade from 0.18.1 to 2.0.0

          Here is the config.xml details . . . :

          On container with Jenkins ver. 2.60.2 and postbuildscript 0.18.1 working:

          
          $ cat ../../jenkins/jobs/test_do_publish/config.xml 
          <?xml version='1.0' encoding='UTF-8'?>
          <project>
            <actions/>
            <description>test call groovy publish</description>
            <keepDependencies>false</keepDependencies>
            <properties/>
            <scm class="hudson.scm.NullSCM"/>
            <canRoam>true</canRoam>
            <disabled>false</disabled>
            <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
            <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
            <triggers/>
            <concurrentBuild>false</concurrentBuild>
            <builders>
              <hudson.tasks.Shell>
                <command>pwd
          ls
          touch results_dummy.xml
          </command>
              </hudson.tasks.Shell>
            </builders>
            <publishers>
              <hudson.tasks.junit.JUnitResultArchiver plugin="junit@1.23">
                <testResults>*.xml</testResults>
                <keepLongStdio>true</keepLongStdio>
                <healthScaleFactor>0.25</healthScaleFactor>
                <allowEmptyResults>false</allowEmptyResults>
              </hudson.tasks.junit.JUnitResultArchiver>
              <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin="postbuildscript@0.18.1">
                <groovyScriptFileList>
                  <org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
                    <filePath>$WORKSPACE/yadda/publish.groovy</filePath>
                  </org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
                </groovyScriptFileList>
                <scriptOnlyIfSuccess>false</scriptOnlyIfSuccess>
                <scriptOnlyIfFailure>false</scriptOnlyIfFailure>
                <markBuildUnstable>false</markBuildUnstable>
              </org.jenkinsci.plugins.postbuildscript.PostBuildScript>
            </publishers>
            <buildWrappers/>
          </project>
          
          

          Different box Jenkins ver. 2.60.3 and postbuildscript@0.17 working:

              <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin="postbuildscript@0.17">
                <groovyScriptFileList>
                  <org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
                    <filePath>$WORKSPACE/testreport.groovy</filePath>
                  </org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
                </groovyScriptFileList>
                <scriptOnlyIfSuccess>false</scriptOnlyIfSuccess>
                <scriptOnlyIfFailure>false</scriptOnlyIfFailure>
                <markBuildUnstable>false</markBuildUnstable>
              </org.jenkinsci.plugins.postbuildscript.PostBuildScript>
          

          NOT working . . . config . .

          container with Jenkins ver. 2.60.2 and PostBuildScript Plugin 2.0.0
          not working, the job fails with "on this node role" message.
          confix.xml is exactly the same as the @0.18.1 config above initially.

          AFTER edit job config in jenkins 2.60.2 with postbuildscript 2.0.0 config.xml changes,
          still not working, the job still fails with "on this node role" message.
          the postbuildscript section has been updated:

              <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin="postbuildscript@2.0.0">
                <config>
                  <genericScriptFiles/>
                  <groovyScriptFiles/>
                  <scriptFiles>
                    <org.jenkinsci.plugins.postbuildscript.model.ScriptFile>
                      <results/>
                      <role>BOTH</role>
                      <filePath>$WORKSPACE/yaddas/publish.groovy</filePath>
                      <scriptType>GROOVY</scriptType>
                    </org.jenkinsci.plugins.postbuildscript.model.ScriptFile>
                  </scriptFiles>
                  <groovyScripts/>
                  <buildSteps/>
                  <markBuildUnstable>false</markBuildUnstable>
                </config>
              </org.jenkinsci.plugins.postbuildscript.PostBuildScript>
          

          #11 job still fails
          "[PostBuildScript] - Build does not have any of the results [] or should not be executed on this node role. Did not execute $WORKSPACE/yadda/.."

          And just to be sure, on this jenkins 2.60.2 box I downgraded plugin to 0.18.1 and after config added back it works:

          [jenkins@ed9dd1196d19 ~]$ diff -u jobs/test_do_publish/config.xml{_postbuildscript2.0.0,_postbuildscriptdowngradeEDITconfig} 
          --- jobs/test_do_publish/config.xml_postbuildscript2.0.0	2017-12-01 12:57:26.568014806 +0000
          +++ jobs/test_do_publish/config.xml_postbuildscriptdowngradeEDITconfig	2017-12-01 13:10:14.372837081 +0000
          @@ -41,22 +41,15 @@
                 <healthScaleFactor>0.25</healthScaleFactor>
                 <allowEmptyResults>false</allowEmptyResults>
               </hudson.tasks.junit.JUnitResultArchiver>
          -    <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin="postbuildscript@2.0.0">
          -      <config>
          -        <genericScriptFiles/>
          -        <groovyScriptFiles/>
          -        <scriptFiles>
          -          <org.jenkinsci.plugins.postbuildscript.model.ScriptFile>
          -            <results/>
          -            <role>BOTH</role>
          -            <filePath>$WORKSPACE/../QA-Test/system_test/regression/run_scripts/do_publish.groovy</filePath>
          -            <scriptType>GROOVY</scriptType>
          -          </org.jenkinsci.plugins.postbuildscript.model.ScriptFile>
          -        </scriptFiles>
          -        <groovyScripts/>
          -        <buildSteps/>
          -        <markBuildUnstable>false</markBuildUnstable>
          -      </config>
          +    <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin="postbuildscript@0.18.1">
          +      <groovyScriptFileList>
          +        <org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
          +          <filePath>$WORKSPACE/../QA-Test/system_test/regression/run_scripts/do_publish.groovy</filePath>
          +        </org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
          +      </groovyScriptFileList>
          +      <scriptOnlyIfSuccess>false</scriptOnlyIfSuccess>
          +      <scriptOnlyIfFailure>false</scriptOnlyIfFailure>
          +      <markBuildUnstable>false</markBuildUnstable>
               </org.jenkinsci.plugins.postbuildscript.PostBuildScript>
             </publishers>
             <buildWrappers/>
          
          Show
          jamesco James Coleman added a comment - Thanks Daniel, I think it is maybe because I am using an older release of jenkins (Jenkins ver. 2.60.2) I upgraded to LTS v2.73.1 and I still had problem with latest PostBuildScript. Downgrade to plugin version 0.18.1 works for me. We will not be able to go past LTS v2.73.1 . . . for a while. If I have time next week I could test with latest jenkins config.xml not sure will it help if the problem is version of jenkins core is too old the PostBuildScript part of the config is cleared out as expected in GUI if I downgrade from 2.0.0 to 0.18.1 the PostBuildScript part of the config is updated as expected in GUI if I upgrade from 0.18.1 to 2.0.0 Here is the config.xml details . . . : On container with Jenkins ver. 2.60.2 and postbuildscript 0.18.1 working: $ cat ../../jenkins/jobs/test_do_publish/config.xml <?xml version= '1.0' encoding= 'UTF-8' ?> <project> <actions/> <description>test call groovy publish</description> <keepDependencies> false </keepDependencies> <properties/> <scm class= "hudson.scm.NullSCM" /> <canRoam> true </canRoam> <disabled> false </disabled> <blockBuildWhenDownstreamBuilding> false </blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding> false </blockBuildWhenUpstreamBuilding> <triggers/> <concurrentBuild> false </concurrentBuild> <builders> <hudson.tasks.Shell> <command>pwd ls touch results_dummy.xml </command> </hudson.tasks.Shell> </builders> <publishers> <hudson.tasks.junit.JUnitResultArchiver plugin= "junit@1.23" > <testResults>*.xml</testResults> <keepLongStdio> true </keepLongStdio> <healthScaleFactor>0.25</healthScaleFactor> <allowEmptyResults> false </allowEmptyResults> </hudson.tasks.junit.JUnitResultArchiver> <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin= "postbuildscript@0.18.1" > <groovyScriptFileList> <org.jenkinsci.plugins.postbuildscript.GroovyScriptFile> <filePath>$WORKSPACE/yadda/publish.groovy</filePath> </org.jenkinsci.plugins.postbuildscript.GroovyScriptFile> </groovyScriptFileList> <scriptOnlyIfSuccess> false </scriptOnlyIfSuccess> <scriptOnlyIfFailure> false </scriptOnlyIfFailure> <markBuildUnstable> false </markBuildUnstable> </org.jenkinsci.plugins.postbuildscript.PostBuildScript> </publishers> <buildWrappers/> </project> Different box Jenkins ver. 2.60.3 and postbuildscript@0.17 working: <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin= "postbuildscript@0.17" > <groovyScriptFileList> <org.jenkinsci.plugins.postbuildscript.GroovyScriptFile> <filePath>$WORKSPACE/testreport.groovy</filePath> </org.jenkinsci.plugins.postbuildscript.GroovyScriptFile> </groovyScriptFileList> <scriptOnlyIfSuccess> false </scriptOnlyIfSuccess> <scriptOnlyIfFailure> false </scriptOnlyIfFailure> <markBuildUnstable> false </markBuildUnstable> </org.jenkinsci.plugins.postbuildscript.PostBuildScript> NOT working . . . config . . container with Jenkins ver. 2.60.2 and PostBuildScript Plugin 2.0.0 not working, the job fails with "on this node role" message. confix.xml is exactly the same as the @0.18.1 config above initially. AFTER edit job config in jenkins 2.60.2 with postbuildscript 2.0.0 config.xml changes, still not working, the job still fails with "on this node role" message. the postbuildscript section has been updated: <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin= "postbuildscript@2.0.0" > <config> <genericScriptFiles/> <groovyScriptFiles/> <scriptFiles> <org.jenkinsci.plugins.postbuildscript.model.ScriptFile> <results/> <role>BOTH</role> <filePath>$WORKSPACE/yaddas/publish.groovy</filePath> <scriptType>GROOVY</scriptType> </org.jenkinsci.plugins.postbuildscript.model.ScriptFile> </scriptFiles> <groovyScripts/> <buildSteps/> <markBuildUnstable> false </markBuildUnstable> </config> </org.jenkinsci.plugins.postbuildscript.PostBuildScript> #11 job still fails " [PostBuildScript] - Build does not have any of the results [] or should not be executed on this node role. Did not execute $WORKSPACE/yadda/.." And just to be sure, on this jenkins 2.60.2 box I downgraded plugin to 0.18.1 and after config added back it works: [jenkins@ed9dd1196d19 ~]$ diff -u jobs/test_do_publish/config.xml{_postbuildscript2.0.0,_postbuildscriptdowngradeEDITconfig} --- jobs/test_do_publish/config.xml_postbuildscript2.0.0 2017-12-01 12:57:26.568014806 +0000 +++ jobs/test_do_publish/config.xml_postbuildscriptdowngradeEDITconfig 2017-12-01 13:10:14.372837081 +0000 @@ -41,22 +41,15 @@ <healthScaleFactor>0.25</healthScaleFactor> <allowEmptyResults> false </allowEmptyResults> </hudson.tasks.junit.JUnitResultArchiver> - <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin= "postbuildscript@2.0.0" > - <config> - <genericScriptFiles/> - <groovyScriptFiles/> - <scriptFiles> - <org.jenkinsci.plugins.postbuildscript.model.ScriptFile> - <results/> - <role>BOTH</role> - <filePath>$WORKSPACE/../QA-Test/system_test/regression/run_scripts/do_publish.groovy</filePath> - <scriptType>GROOVY</scriptType> - </org.jenkinsci.plugins.postbuildscript.model.ScriptFile> - </scriptFiles> - <groovyScripts/> - <buildSteps/> - <markBuildUnstable> false </markBuildUnstable> - </config> + <org.jenkinsci.plugins.postbuildscript.PostBuildScript plugin= "postbuildscript@0.18.1" > + <groovyScriptFileList> + <org.jenkinsci.plugins.postbuildscript.GroovyScriptFile> + <filePath>$WORKSPACE/../QA-Test/system_test/regression/run_scripts/do_publish.groovy</filePath> + </org.jenkinsci.plugins.postbuildscript.GroovyScriptFile> + </groovyScriptFileList> + <scriptOnlyIfSuccess> false </scriptOnlyIfSuccess> + <scriptOnlyIfFailure> false </scriptOnlyIfFailure> + <markBuildUnstable> false </markBuildUnstable> </org.jenkinsci.plugins.postbuildscript.PostBuildScript> </publishers> <buildWrappers/>
          Hide
          dheid Daniel Heid added a comment -

          Hi James,

          now I got it!!!

          The problem is not the wrong role, but the missing build results:

          <results/>
          

          The Groovy script won't be executed, because the build result (I assume it is "SUCCESS") doesn't match the settings. This was one of the improvement requests: The users wanted to execute individual scripts for each kind of result (e.g. ABORTED). The old version only allows this setting for the whole bunch of scripts (scriptOnlyIfSuccess and scriptOnlyIfFailure). I still don't understand, why your settings work:

          <scriptOnlyIfSuccess>false</scriptOnlyIfSuccess>
          <scriptOnlyIfFailure>false</scriptOnlyIfFailure>
          

          should not execute anything. But I does apparently.

          The "on this node" message combines two states: Either the build result does not fit or the role is not correct. I will try to split these messages to make it better understandable.

          Please try again and select a build result explicitly via the GUI. If the <results/> section won't be changed, there is indeed a bug. This worked for me the last time I tried to save a Groovy script.

          By the way: The version 2.1.0 is now available. It is fully compatible to 2.0.0

          Show
          dheid Daniel Heid added a comment - Hi James, now I got it!!! The problem is not the wrong role, but the missing build results: <results/> The Groovy script won't be executed, because the build result (I assume it is "SUCCESS") doesn't match the settings. This was one of the improvement requests: The users wanted to execute individual scripts for each kind of result (e.g. ABORTED). The old version only allows this setting for the whole bunch of scripts (scriptOnlyIfSuccess and scriptOnlyIfFailure). I still don't understand, why your settings work: <scriptOnlyIfSuccess> false </scriptOnlyIfSuccess> <scriptOnlyIfFailure> false </scriptOnlyIfFailure> should not execute anything. But I does apparently. The "on this node" message combines two states: Either the build result does not fit or the role is not correct. I will try to split these messages to make it better understandable. Please try again and select a build result explicitly via the GUI. If the <results/> section won't be changed, there is indeed a bug. This worked for me the last time I tried to save a Groovy script. By the way: The version 2.1.0 is now available. It is fully compatible to 2.0.0
          Hide
          jamesco James Coleman added a comment -

          OH! :-D That works. Simple!
          I didn't actually recognise the new result scroll selection widget as a selection widget!
          I don't feel too bad as another person here didn't spot it!

          By default no results are selected which means the script will never be called.
          I wonder if you could make the default new config select at least one or maybe all the possible results except aborted so it's same behaviour coming from old to new version without changing config?
          Might help other somewhat stupid users like myself! :-7 :-P
          No bother if you can't.

          This is a cool feature actually!
          Different options for each script is really useful.
          Most of our few post-build scripts have some groovy logic at the top checking build result and causing different actions.
          Nice to have that done in plugin! And the abort option is cool. When we abort some jobs we leave sometimes long-running test/tools behind and have not been able to come up yet with a nice way of cleaning them up. So maybe now we can

          Coolaboola! Thanks!

          Show
          jamesco James Coleman added a comment - OH! :-D That works. Simple! I didn't actually recognise the new result scroll selection widget as a selection widget! I don't feel too bad as another person here didn't spot it! By default no results are selected which means the script will never be called. I wonder if you could make the default new config select at least one or maybe all the possible results except aborted so it's same behaviour coming from old to new version without changing config? Might help other somewhat stupid users like myself! :-7 :-P No bother if you can't. This is a cool feature actually! Different options for each script is really useful. Most of our few post-build scripts have some groovy logic at the top checking build result and causing different actions. Nice to have that done in plugin! And the abort option is cool. When we abort some jobs we leave sometimes long-running test/tools behind and have not been able to come up yet with a nice way of cleaning them up. So maybe now we can Coolaboola! Thanks!
          Hide
          dheid Daniel Heid added a comment -

          You're right. A default option would be very useful. I will add it.

          The messages are split now, so there will be no more confusion.

          Nice to hear, that the feature is useful for you, too. This was one of the most wanted features, I think.

          You're welcome!

          Show
          dheid Daniel Heid added a comment - You're right. A default option would be very useful. I will add it. The messages are split now, so there will be no more confusion. Nice to hear, that the feature is useful for you, too. This was one of the most wanted features, I think. You're welcome!

            People

            • Assignee:
              dheid Daniel Heid
              Reporter:
              jason_m_may Jason May
            • Votes:
              4 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: