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

plugin should wait, as long as the triggered remote-job is waiting for an free build processor

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • Jenkins Version: 1.617
      Parameterized Remote Trigger Plugin: 2.2.3
      OS: Windows7 64bit
      Java Version: 1.8.0_51

      Hi,

      I want to suggest an enhancement when triggering a remote job. In my situation the current version of this plugin doesn't work like expected. Let me describe this situation briefly:

      Assuming two jenkins A and B which are working as build servers and a third jenkins C which is working as test server.

      Configuration A:

      • Job A1 -> perform any build process and starts two remote jobs C1 and C2 in parallel on C
      • Job A2 -> is waiting of C1 and C2
      • A uses the join plugin

      Configuration B:

      • Job B1 -> perform any build process and starts one remote job C3

      Configuration C:

      • Job C1 -> test job 1 -> use Test-Hardware1
      • Job C2 -> test job 2 -> use Test-Hardware2
      • Job C3 -> test job 3 -> use Test-Hardware1
      • C has on master node with 2 build executors (processors) -> one build executor per Test-Hardware to avoid parallel execution, because the test hardware couldn't be shared.
      • that means Job C1 and C2 can be executed in parallel
      • and Job C1 and C3 only sequential

      Now assuming jenkins A starts the two remote jobs C1 and C2 while job C3 is running.
      This means C1 have to wait in the BuildQueue until job C3 is finished, C2 could be started directly.

      In this situation the parameterized remote trigger plugin doesn't consider, if a job is waiting in the build queue and starts an old buildnumber instead. I would expect, that the plugin have to wait (maybe optionaly) even if the remote job is hanging in the buld queue?!

      I solved the issue with the following code snippet (added to function 'perform'):

      		//wait until remote job is removed assigned to a build executor
      		boolean jobIsWaiting = true;
      		while (jobIsWaiting) {
      			JSONObject testResponse = sendHTTPCall(queryUrlString, "GET", build, listener);
      			if (testResponse != null) {
      				JSONObject queueObj = testResponse.getJSONObject("queueItem");
      				if( queueObj.toString() != "null" ) {
      					Map<String,String> out = new HashMap<String, String>();
      					parse(queueObj, out);
      					listener.getLogger().println("The remote job " + jobName + " is: " + out.get("why"));
      					listener.getLogger().println("Waiting for " + this.pollInterval + " seconds until next retry.");
      					try {
      						Thread.sleep(this.pollInterval * 1000);
      					} catch (InterruptedException e) {
      						this.failBuild(e, listener);
      					}
      				}
      				else {
      					jobIsWaiting = false;
      					listener.getLogger().println("Job is not in build queue. Proceed normally.");
      				}
      			}
      			else {
      				//This should not happen as this page should return a JSON object
      				this.failBuild(new Exception("Got a blank response from Remote Jenkins Server [" + remoteServerURL + "], cannot continue."), listener);
      			}
      		}
      

      The function parse is defines as followed:

      	private Map<String,String> parse(JSONObject json , Map<String,String> out){
      		Iterator<String> keys = json.keys();
      		while(keys.hasNext()){
      			String key = keys.next();
      			String val = null;
      			try{
      				 JSONObject value = json.getJSONObject(key);
      				 parse(value,out);
      			}catch(Exception e){
      				val = json.getString(key);
      			}
      
      			if(val != null){
      				out.put(key,val);
      			}
      		}
      		return out;
      	}
      

      New imports:

      import java.util.Map;
      import java.util.HashMap;
      import java.util.Iterator;
      

      With these changes the plugin is working in my situation and produces the following outputs.

      Output if the job C1 is not waiting:

      ...
      Triggering this remote job: C1
      Checking that the remote C1 is not currently building.
      Remote job remote job C1 is not currenlty building.
      Triggering remote job now.
      Remote Jenkins server returned empty response or invalid JSON - but we can still proceed with the remote build.
      Job is not in build queue. Proceed normally.
      Checking parameters of #91
      This job is build #[91] on the remote server.
      Blocking local job until remote job completes
      Remote build started!
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      ...
      

      Output job C2 is waiting of free executor:

      ...
      Triggering this remote job: C2
      Checking that the remote job C2 is not currently building.
      Remote job remote job C2 is not currenlty building.
      Triggering remote job now.
      Remote Jenkins server returned empty response or invalid JSON - but we can still proceed with the remote build.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      The remote job C2 is: Waiting for next available executor
      Waiting for 10 seconds until next retry.
      Job is not in build queue. Proceed normally.
      Checking parameters of #29
      This job is build #[29] on the remote server.
      Blocking local job until remote job completes
      Remote build started!
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      Waiting for remote build to finish.
      Waiting for 10 seconds until next poll.
      ...
      

      The complete source file is attached to this issue. Pleas review theses changes. If you need some more information don't hesitate to contact me.

      Regards
      Silvio

            morficus Maurice W.
            svo Silvio Voitzsch
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: