Last active
August 29, 2015 14:01
-
-
Save roosto/a6a76dbad0816586eeaa to your computer and use it in GitHub Desktop.
Reload Jenkins Login Page Bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************** | |
Dustin Masterson aka @roosto | |
If you have been logged out of jenkins and you open your browser and your | |
browser reopens a slew of tabs from your jenkins instance, each page will | |
redirect you to a login page. | |
Annoyingly even after you login on one of these login pages, reloading | |
another page will still load the login page, instead of the page that you | |
would be redirected if you had logged in via that page. | |
This bookmarklet pulls out the URI to redirect you to and then redirects you | |
there without you needing to log back in from that page. | |
e.g, if you are actually logged in and on the page: | |
https://jenkins.example.com:8080/jenkins/login?from=%2Fjenkins%2Fjob%2FMyAwesomeJenkinsJob%F | |
reloading will only reload that page, even though you probably want to get to: | |
https://jenkins.example.com:8080/job/MyAwesomeJenkinsJob/ | |
This bookmarklet does exactly that. | |
You will need to fill in `jenkinsHost` and `jenkinsRootURI` with values for | |
your server. | |
`jenkinsHost`: should be set to your server name, complete with protocol | |
and port number, if you are using a non-standard port | |
`jenkinsRootURI: set to '/jenkins/' or '/' if you do not have the jenkins | |
root set to a specific directory | |
You may find John Gruber’s excellent JavaScript Bookmarklet Builder helpful | |
for wrangling this, or any other javascript bookmarklets: | |
http://daringfireball.net/2007/03/javascript_bookmarklet_builder | |
Gruber’s Perl source is available as a Gist: | |
https://gist.github.com/gruber/8658935 | |
************************/ | |
// ↓ Thar be the the bookmarklet, if your jenkins is at https://jenkins.exmaple.com:80880/jenkins/ | |
// javascript:var%20jenkinsHost%20=%20%27https://jenkins.example.com:8080%27;var%20jenkinsRootURI%20=%20%27/jenkins/%27;var%20pageURL%20=%20location.href;var%20matches%20=%20/login(\?[^&]*from=([^&#]*))?/.exec(pageURL);if%20(%20matches%20===%20null%20||%20pageURL.indexOf(jenkinsHost%20+%20jenkinsRootURI)%20==%20-1%20)%20{alert(%27Does%20not%20seem%20to%20be%20a%20Jenkins%20login%20page%27);}else%20{var%20targetURI;if%20(%20!%20matches[2]%20)%20{targetURI%20=%20jenkinsRootURI;}else%20{targetURI%20=%20decodeURIComponent(matches[2]);}location.assign(jenkinsHost%20+%20targetURI);} | |
var jenkinsHost = 'https://jenkins.example.com:8080'; | |
var jenkinsRootURI = '/jenkins/'; | |
var pageURL = location.href; | |
var matches = /login(\?[^&]*from=([^&#]*))?/.exec(pageURL); | |
if ( matches === null || pageURL.indexOf(jenkinsHost + jenkinsRootURI) == -1 ) { | |
alert('Does not seem to be a Jenkins login page'); | |
} | |
else { | |
var targetURI; | |
if ( ! matches[2] ) { | |
targetURI = jenkinsRootURI; | |
} | |
else { | |
targetURI = decodeURIComponent(matches[2]); | |
} | |
//decodeURIComponent(results[1].replace(/\+/g, " ") | |
location.assign(jenkinsHost + targetURI); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment