3

I want to give a live update of my job-build using the jenkins progress bar and currently the progress bar is not current but based on average.

How can I achieve the same?

I could not find any answer on any platform over the web, If anyone has a solution, please answer.

Jomon Johny
  • 53
  • 1
  • 10

1 Answers1

-4

You can grab the current value of job's progress via powerful API:

simply use http request:

http://<host>/job/<jobname>/lastBuild/api/json?tree=executor[progress]

When job is not running, answer will be null:

{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowRun","executor":null}

When job is running, the value will be in progress parameter:

{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowRun","executor":

{"_class":"hudson.model.OneOffExecutor","progress":18}}

"progress":18 means 18% of completeness

See relevant question here: how to get progress bar data for a running jenkins job through the API

To see all opportunities of API, just add /api/ in the link of any of your job:

http://<host>/job/<jobname>/api/
Sysanin
  • 1,501
  • 20
  • 27
  • 1
    This would help me while retrieving the progress of a task, How could I update the progress value, is there a rest contract for that as well? – Jomon Johny Dec 11 '18 at 22:58
  • 2
    @JomonJohny sorry, I made fast read of your question and didn't get the main idea that you are looking for `set the build progress`, not the `get progress value`. As I understand you can only manipulate of status of any build via passing current state. For example, for each build `currentBuild.result` is writable property, so you can set the value as you wish: SUCCESS, UNSTABLE, or FAILURE. also, may be `null` for an ongoing build. But it still will be calculate the progress bar in average. Also you can try to check the Jenkins source code for any related functions in Jenkins core. – Sysanin Dec 12 '18 at 09:38
  • @JomonJohny could you please give an example or details? Maybe I don't understand your question correctly. Are you talking about jenkins simple job or jenkins pipeline? or any external job? Which type of item you are talking about? – Sysanin Dec 12 '18 at 09:43
  • I will explain everything in detail, I am running a job where using a java program I am navigating menu items of a product using selenium webdriver. Now I need to provide a real time update to the end user who is triggering the job about the percentage of menu items I have traversed so far , Right now as you pointed out, it is based on average. Whereas, I want live update regarding the traversal task by the program that is being executed as a build step in the Jenkins Job. The job is a simple job, and the build steps are calling my program using cmd. – Jomon Johny Dec 12 '18 at 12:54
  • 1
    @JomonJohny that sounds more clearly. thanks. from what i'm seeing now, here is my suggestions: use jenkins pipeline job to run your cmd java program, in pipeline you can describe `stage` sections for each call of java programs. or, it if has only one call per run, you can save progress from your java application somewhere outside and then in each pipeline `stage` check the completed steps and complete `stages` in pipeline. this is sounds odd, but it can work. also, try to check `Gradle` - it can help you run the selenium tests on Java via Jenkins. – Sysanin Dec 12 '18 at 13:05
  • 1
    a bit more about `gradle` here: you can describe gradle tasks as selenium tests and then run them step-by-step, each as `stage` in jenkins pipeline. In sum you will see results of each step of your program, because gradle run returns success/fails from you java selenium tests. try to google `run end to end selenium tests with gradle` – Sysanin Dec 12 '18 at 13:09