I have set up a way for my team to click on some links to trigger some jenkins jobs. For this I have used the "Trigger builds remotely (e.g., from scripts)" option
I need to send an email after that detailing who triggered the job, but I have noticed that triggering this way the cause gets registered as Cause.RemoteCause instead of Cause.UserIdCause. This does not have info on the user who triggered it, even though they need to log in.
I have not been able to find any other way of getting the user's name. Is it even possible with remotely triggered builds? If so, how would I do it?
Thank you in advance
Related
Using Jenkins 2.277.2 (LTS) and Extended E-mail Notification and build user vars plugins I'm trying to send emails before build to notify build-user that job is started and also after success/fail.
Problem is that I need to use ${BUILD_USER_ID} variable and it does not get exposed for Before Build trigger. For any other triggers that I tested (always, failure - any, success) it is exposed correctly, however all of those emails are being sent after the build, and I need to notify build-user that job is started.
Any ideas how to achieve that? Ideally without any more plugins installation, but if there's no way - that's kind of acceptable too.
Thanks.
upd It'd probably be easier for me to illustrate what I meant - here's how it looks https://i.imgur.com/YdG1N9C.png
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
We are using Jenkins with Pipeline Jobs and of course the awesome Jenkinsfile.
Twice now a developer accidentally clicked on the build button, which ended up causing a bit of chaos. I am trying to figure out if it is possible to have something like a popup that asks "Do you really want to start this build?".
Any ideas on this user related issue are welcome.
Have a look at the article Controlling the Flow with Stage, Lock, and Milestone in the Jenkins blog, which covers a bit more than only asking for confirmation.
Essentially, there is the input step, which requires user input to continue pipeline execution.
The problem with the input step as suggested by StephenKing is that you won't be able to run the build automatically anymore as it will always ask for the user to confirm the input step manually. This prevents "automatic builds" triggered e.g. by webhooks or CRON jobs.
One workaround is to have a timeout and the build is triggered if the timeout is over. Like that, a user can at least abort an unintended build. But this leads to significantly longer build times.
What we did in my old company was, that we created a so called "parametrized" build, which had a simple checkbox "Do you really want to build this job" that resulted in a flag REALLY_BUILD as an environment variable. You can then ask for ${REALLY_BUILD}==1 in the Jenkinsfile. Every time a developer triggers a build, he has to check the box, otherwise the build will not start / immediately stop.
When you trigger your job via a webhook, you can pass a parameter REALLY_BUILD as an URL parameter (see this comment in the Jenkins tracker) and access it in the Jenkinsfile as before.
Here is another resource for how to use parameters in Pipelines.
We're using Jenkins and Slack.
I'm trying to setup a slack notification about a build, and I would like the notifucation to include more information - so I resort to the custom message.
I found about $GIT_BRANCH and $BUILD_NUMBER and $JOB_NAME and other interesting guys, and put them to use.
But I lack a way to mention the cause that triggered the build - be it a polling on the scm, or a user that pressed build now.
The later is of extreme importance - especially in jobs that deploy to a target environment...
Can anybody recommend me a way to detect the triggering cause and add it to the custom message?
BTW - I'd want this information not only for slack notification.
I'd like to add this information to a signature file that we add to every artifact (as well as other things)
Use the Build User Vars Plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin
You will have the variables:
BUILD_USER – full name of user started build,
BUILD_USER_FIRST_NAME – first name of user started build,
BUILD_USER_LAST_NAME – last name of user started build,
BUILD_USER_ID – id of user started build.
*If you want to get it from other job you can use the below URL:
http://[jenkins-server]/job/[job-name]/[build-number]/api/xml?xpath=(//action/cause/shortDescription)
It will directly return the line:
< shortDescription>Started by user foobar< /shortDescription>
Is there a way to get the hudson job initiated user name.
Is it possible to get using script shell, py etc.
Lets assume I have the build # which was initiated. I know how to get the latest build info using api but would like to get a user details for a specific job.
Do you think, this will work for hudson? :)
https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin
Thanks in advance
That plugin will not work with Hudson, unless you download a very old version of the plugin. I'm not sure how many people are still using Hudson and haven't upgraded to Jenkins.
Anyway, when a user manually triggers a build, this is called a "user cause"; there are other types of cause, e.g. SCM trigger.
You can use the JSON or XML API to get the causes for a build, for example:
https://ci.jenkins-ci.org/job/remoting/lastSuccessfulBuild/api/xml?xpath=//action/cause/userId
In this case, this returns the username that caused the build to run.
Though note that there may be multiple causes for a build, and potentially other cause types that use the userId field.
This works in Jenkins, but it should also work in Hudson, but I haven't tested it.