How can I make an external job appear on a Jenkins dashboard more like a native Jenkins job, specifically including a progress 'bar'?
I've come across https://plugins.jenkins.io/external-monitor-job but this only appears to provide a way to say
My jobs has finished with this console output and this result code.
I would also like to see things such as current progress. Or to put it another way, I'd like my external job to be able to appear on something like https://kj187.github.io/dashing-jenkins_job/ in a similar manner to a native Jenkins job.
So is it possible to push more data than the external-monitor-job suggests?
Create a free style job and monitor the external process (print logs etc.) in the free style job - read the logs till logical conclusion in the freestyle job
What about pipeline view plugin?
Steps will be:
v1 (manual way)
create a job called monitoring_external_process inside pipeline view. This job performs a kind of ping looking the end of your process.
start your external process in a separate way.
go to jenkins monitoring_external_process job and press build.
a progress bar will be showed until the end of your external process.
v2 (automatic way)
create a job called monitoring_external_process inside pipeline view. This job performs a kind of ping looking the end of your process.
configure a webhook trigger or remote build for this job. This enable a public url to invoke the jenkins job. (See link reference #2)
configure your external process to perform an htttp request to the public url.
start your external process in a separate way.
Automatically your job will be started and progress bar will be showed until the end of your external process.
References:
(1) https://code-maven.com/jenkins-pipeline-hello-world
(2) https://jrichardsz.github.io/devops/devops-with-git-and-jenkins-using-webhooks
Related
Is there a way where to store some metadata from Jenkins pipeline job, e.g:
We have a Jenkinsfile which builds a gradle project, creates docker image and pushes it to google cloud
Then a "Subjob" is launched which runs integration tests (IT) on that docker image. Subjob receives a couple of parameters (one of them - the generated docker image name)
Now sometimes that IT job fails, and I would like to re-run it from the main job view, so idealy:
we have a plugin which renders a custom button in blue ocean UI on the main job
By clicking that button a subjob is invoked again with the same parameters (plugin queries the jenkins api, get params of this job, and resubmits the subjob).
The problem ? How to get/set those parameters. I could not seem to find a mechanism for that, expect artifact storage. I could get away with that by creating a simple json/text file and uploading it as artifact, and then retrieving it in my plugin, but maybe there is a better way?
Stage restart is not coming to Scripted Pipelines so that does not look like ant option.
Maybe you can use the Jenkins API to get the details of the build?
https://your_jenkins_url.com/job/job_name/lastBuild/api/json?pretty=true
Instead of lastBuild you can also use the build number or one of lastStableBuild, lastSuccessfulBuild, lastFailedBuild, lastUnstableBuild, lastUnsuccessfulBuild, lastCompletedBuild
There is a parameters key there with all parameter names and values used in the build.
More details on https://your_jenkins_url.com/job/job_name/api/
Also, any reason you can't use the replay button in the IT job?
we have jenkins CICD automated pipelines working great. we also trigger it via REST API with build Parameters.
Now, we have JIRA dashboard having custom workflow created where developers moves or changes queue of issues/stories to "ReadyForDeployment" once development is completed.
Now here, once developer moves queue to "ReadyForDeployment" :-
JIRA should prompt for 3 fields (ENV, PACKAGE_NAME_APP and
PACKAGE_NAME_DB) those will be placed in jenkins URL like
blahblahblah/buildWithParameters?ENV=${ENV}& PACKAGE_NAME_APP=${PACKAGE_NAME_APP}&PACKAGE_NAME_DB=${PACKAGE_NAME_DB}
Basically upon queue change,webhook should be triggered whcih
will take input/parameters from JIRA itself.
Please let me know your thoughts on this.
It depends on your requirement whether its correct or not. But it can be possible to trigger jenkins from Jira useing Jira-weebhook and passing the parameters.
https://developer.atlassian.com/jiradev/jira-apis/webhooks
I occasionally want to get notified when a particular jenkins job that is building finishes. Is there any way to do this?
Scripting it through the API would be fine. I already have the jenkins IRC bot that notifies me of many things, so if I could just dynamically modify the running job build, that would be enough to do what I want -- I'm just having a hard time finding how to accomplish that.
AFAIK, you cannot change a job's config while it's running.
Here is an idea: Use a post-build step to check for an external resource status (like a file containing an action by text) and running an action based on the content of the file.
The external file can be modified while the build is running, so when the post-build is executed, it will follow the logic defined based on the content of the file.
I hope this helps.
You can use email notifier, It will send you an email
https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin
I am new to Jenkins plugin development. M trying to write a plugin that should be executed before any Multi configuration type job runs in Jenkins.
In this plugin I want to write rules that will check what configuration parameters user has selected while submitting the job, based on selected parameters, I want to decide whether to allow the job to run or to restrict it.
User should be shown reason as to why that job cannot be run in the Console Output.
Does anyone have any ideas which class I need to extend or which interface I need to implement in order to get a hook into Jenkins job run?
You could look at the Matrix Execution Strategy which allows for a groovy script to select which matrix combinations to run. I would think if your script threw an exception it would stop the build.
For background, the multi configuration projects run a control job (or flyweight) which runs the SCM phase then starts all the actual combinations. This plugin runs after the flyweight SCM checkout.
If nothing else, this will give you a working plugin to start from
Disclaimer: I wrote this plugin
Blocked queue job plugin was what I needed
Out of the box that plugin supports two ways to block the jobs -
Based on the result of last run of another project.
Based on result of last run of the current project
In that plugin the BlockQueueItemTaskDispatcher.java extends Jenkin's QueueTaskDispatcher providing us a hook into Jenkins logic to allow or block the jobs present in the queue from running.
I used this plugin as a starting point for developing a new plugin that allows us to restrict project based on parameters selected and the current time. Ultimate goal is to restrict production migrations from running during the day.
Overriding the isBlocked() method of QueueTaskDispatcher gave access to hudson.model.Queue.Item instance as an argument to me. Then I used the Item instance's getParams method to get access to build parameters selected by the user at runtime. Parsed the lifecyle value from it. Checked the current time. If lifecycle was Production and current time was day time then restricted the job by returning non null CauseOfBlockage from isBlocked() method. If that condition was false, then returnedCauseOfBlockage as null allowing the queued job to run.
What is the best way to allow jenkins to act on something when a event happens, meanwhile it can wait for the event?
I was thinking of writing an ant script that can prob a process that it started to see if it had completed yet before moving onto another task, but I'm not sure it's a good idea to do that, perhaps just use a shell script? Just wanted to know what is your experience with doing something like that.
Jenkins should not wait. A job build should be triggered from the 'something' event. This can be acomplished by a wget on an URL like http://jenkins.myserver.com:8080/job/myjob/buildWithParameters?delay=0sec&myparm=42. You can also use the jenkins CLI.
try this plugin: https://plugins.jenkins.io/webhook-step/
As per the documentation: This pipeline plugin provides an easy way to block a build pipeline until an external system posts to a webhook. It can be used to integrate long running tasks into a pipeline, without busy waiting.