Logging Who Restarted Jenkins - jenkins

Is there a way to log who ordered a Jenkins restart? The log right now just denotes that a restart happened. I would like something like
Mar 30, 2015 9:57:01 PM INFO: Safe-restart started by GregWringle.
Is there anyway I can implement this?

Jenkins does this various restarts, but for restart after installing a plugin it puts the user as anonymous. There's an audit plugin that records the user name.

Related

Why is my Jenkins TFS polling time in the future?

I have a jenkins job that is polling my TFS server. My TFS Server lives on AWS. It is finding changes that are happening in the future and starting my job. Here is what is displayed in the TFS Polling log.
Started on Sep 8, 2016 10:46:09 AM
Done. Took 0 ms
Changes found
Inside of my build console for this job shows this which makes me believe something is running on GMT time as it is exactly 6 hours ahead of my current timezone (MDT).
Querying for remote changeset at '$/XXXXXXXXX/Three/Dev' as of 'D2016-09-08T16:46:15Z'...
Query result is: Changeset #98532 by 'XXXXXXX' on '2016-09-08T13:58:27Z'.
It's stuck in an endless loop because that value is always in the future. I have checked everything to make sure it is on the correct timezone (Jenkins Master, Jenkins Node(slave), the Linux box Jenkins Master is installed on, the TFS server (front and backend)) I thought about setting the timezone for jeknins to GMT but that would mean all the jobs we have that run at certain times of the day would start to fail.
From my test, the date and time in Console Output of Jenkins build is GMT time by default. There is nowhere to change this. If you check TFS log, you'll find it also use GMT time in log file and no where to change this.

Plugin works in local server but doesn't work in production server

I've a created a plugin with a button which does some task when clicking it. I've put this plugin in my local Jenkins (/jenkins/plugins) location and then restarted server.
The button appears on every job page, but When I put the same plugin in production server and restart it, the button doesn't appear.
Both my local Jenkins and production Jenkins have same version (2.7.1)
I put plugin.jar and plugin.hpi files in /jenkins/plugins location
Can anyone have idea whats the problem. How can I debug it?
You should be able to create a log by going to:
Manage Jenkins > System Log > Add a New Log Recorder.
Check the System Log for any loggers that are printing warnings during the Jenkins boot process, add them to the Log Recorder, and adjust the logging level to your liking.
https://wiki.jenkins-ci.org/display/JENKINS/Logging

Jenkins Multibranch Pipeline - GitHub Enterprise Issues?

I have spent days troubleshooting/researching this issue. I can't seem to figure out what's going on here. I'm trying to setup a multibranch pipeline project pointed at our internal GitHub enterprise servers. The same issue occurs in other project types too like the "GitHub Organization". It's some sort of security issue that I can't figure out.
Let's start with what I know...
I have (to my knowledge) configured the GitHub Plugin configuration correctly with a TOKEN (also configured per documentation)... I can successfully "Verify Credentials" and it comes back successful. http://imgur.com/br13adk
I keep getting this validation issue on the GitHub Enterprise Servers Validation
http://imgur.com/GnffTeV
I can connect successfully to any ONE repository hosted on my enterprise github server. When I try to configure a multi-branch project from a GitHub source, I ALWAYS get BLANK for repositories....
http://imgur.com/2Q9s1mo
I configured a custom logger to see what was going on and it seems like the branch source plugin is always going out to api.github.com...
Jan 25, 2016 11:48:23 AM WARNING org.jenkinsci.plugins.github_branch_source.Endpoint$DesciptorImpl doCheckApiUri
Jan 25, 2016 11:48:23 AM WARNING org.jenkinsci.plugins.github_branch_source.Endpoint$DesciptorImpl doCheckApiUri
Jan 25, 2016 11:54:58 AM WARNING org.jenkinsci.plugins.github_branch_source.AbstractGitHubSCMSource$AbstractGitHubSCMSourceDescriptor doFillRepositoryItems
Server returned HTTP response code: 401 for URL: https://api.github.com/user
Jan 25, 2016 11:54:58 AM WARNING org.jenkinsci.plugins.github_branch_source.AbstractGitHubSCMSource$AbstractGitHubSCMSourceDescriptor doFillRepositoryItems
Server returned HTTP response code: 401 for URL: https://api.github.com/orgs/nhudacin
Jan 25, 2016 11:54:58 AM WARNING org.jenkinsci.plugins.github_branch_source.AbstractGitHubSCMSource$AbstractGitHubSCMSourceDescriptor doFillRepositoryItems
Server returned HTTP response code: 401 for URL: https://api.github.com/users/nhudacin
I've configured the API endpoint for the GitHub plugin (as seen in the first screen shot), for the PR Builder plugin and the credentials are working (or so it seems). I'm thinkin it's a probably with the enterprise API endpoint configuration.
Any help?? I'm going CRAZY here!
I'm having a similar issue as Nick H.
In my production Jenkins instance
Jenkins version 2.17 Latest weekly release with all plugins up to date as of Aug 10 i.e
GitHub Branch Source Plugin 1.8.1
PipelineMultibranch 2.8
I get :
WARNING: Server returned HTTP response code: -1, message: 'null' for URL: https://api.github.com/users/ORG
Even when I have configured the API endpoint on GitHub Enterprise Servers to be http://github.MYDOMAIN/api/v3/
On the other hand, on a fresh local install of Jenkins
with the same configuration I get:
Aug 11, 2016 3:19:14 PM org.jenkinsci.plugins.github_branch_source.GitHubSCMSource$DescriptorImpl doFillRepositoryItems
WARNING: Exception retrieving the repositories of the owner ORG on with credentials USER/****** ( test credentials)
Edit: I found a way to make it work, it was not very intuitive, I found it after browsing the code and matching the strings to the plugin UI
What you need to do is, after you get the Invalid credentials red error press Advanced... button
Then a combo box with the API endpoints defined in the Manage Jenkins-> Configure System -> GitHub Enterprise Servers will appear.
Select the API endpoint for you GitHub Enterprise instance, choose Checkout credentials that have access to that instance and the list of all the repositories will appear.
Save it, and start a Branch indexing discovering the branches that have a JenkinsFile on it.
NOTE: in order to have this working every push a web hook needs to be installed in github Enterprise, you can do that by going
Manage Jenkins-> Configure System -> GitHub and press the second Advanced... button
Now a Re-register hook for all jobs button will appear. Just press that and it should add the hook that will be triggered every time you push into your matching repos.
Hope this helps
I don't have much knowledge about this particular scenario, but in this commit you can see, that they switched from regex validation to anonymous connection to endpoint. And if your server is in private mode, it will fail.

Jenkins Error Log in GrayLog2

We are noticing that any errors that occur in our Jenkins service go unattended until it is too late and we were looking for a way to get our Jenkins error log on our server into GrayLog2. Are there any plugins or scripts that will handle this for us?
Your question is for Graylog2, but we have been using HipCHat to get real time updates from Jenkins about builds etc. (we also use it to get GIT activity on projects from Stash).
I would highly recommend it as an alternative if you do not win with GrayLog2.

What would happened if jenkins get restarted at the time of execution of jenkins job

Suppose i have set a Jenkins job from 12 pm to 1pm. Let us say job has been started. Now suppose Administrator has set Jenkins to be restarted at 12:30 PM. What would happen- will my script gets paused or gets failed?
Surely your builds will abort if jenkin is going for a restart/shutdown. I have seen some cases where you lose even the build log for that particular build.
(jenkins_url)/safeRestart. This will allow all running builds to complete.
(jenkins_url)/restart will force a restart without waiting for builds to complete.

Resources