Skip to content

Commit

Permalink
jenkins configure url
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyzhang committed May 21, 2019
1 parent 2f09d5c commit af9fa48
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
31 changes: 20 additions & 11 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ File me [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/issues][Iss
| Run job in different agents | =node($agent_label) {...}= |
| Ask for user input | =stage('stage2'){ input "OK to go?" }= |
| Actively fail current pipeline job | =error("Build failed because of this and that..")= |
| [[https://stackoverflow.com/questions/43875093/check-if-property-exists-groovy][Check whether property exists]] | =if (env.keep_failed_env)= |
| [[https://stackoverflow.com/questions/47039924/jenkins-pipeline-enable-timestamps-in-build-log-console][Jenkins Pipeline enable timestamps]] | =options{timestamps()}= |
| Keep going when previous stage has failed | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/keep-going-with-errors.groovy][keep-going-with-errors.groovy]] |
| Send slack notification in pipeline | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/slack-notification.groovy][slack-notification.groovy]] |
| Pass parameter across jenkins jobs | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/jenkinsfile-pass-parameter.groovy][jenkinsfile-pass-parameter.groovy]] |
Expand Down Expand Up @@ -60,13 +62,13 @@ File me [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/issues][Iss
| Manage jenkins jobs | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/manage-jenkins-jobs.groovy][manage-jenkins-jobs.groovy]] |
| Cancel queued jenkins jobs by regexp | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/kill-queued-jenkins.groovy][kill-queued-jenkins.groovy]] |
** Jenkins Security Via Groovy
| Name | Comment |
|------------------------------------------+------------------------------------------|
| logged-in users can do anything | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/logged-in-users.groovy][logged-in-users.groovy]] |
| [[https://wiki.jenkins.io/display/JENKINS/LDAP+Plugin][Enable ldap in Jenkins]] | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/enable-ldap.groovy][enable-ldap.groovy]] |
| Create a jenkins secret text | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/create-secret-text.groovy][create-secret-text.groovy]] |
| Configure authorization in Jenkins | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/matrix-authorization-strategy.groovy][matrix-authorization-strategy.groovy]] |
| [[https://stackoverflow.com/questions/35960883/how-to-unlock-jenkins][Jenkins skip wizzard when initialization]] | =-Djenkins.install.runSetupWizard=false= |
| Name | Comment |
|------------------------------------------+----------------------------------------|
| logged-in users can do anything | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/logged-in-users.groovy][logged-in-users.groovy]] |
| [[https://wiki.jenkins.io/display/JENKINS/LDAP+Plugin][Enable ldap in Jenkins]] | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/enable-ldap.groovy][enable-ldap.groovy]] |
| Create a jenkins secret text | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/create-secret-text.groovy][create-secret-text.groovy]] |
| Configure authorization in Jenkins | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/matrix-authorization-strategy.groovy][matrix-authorization-strategy.groovy]] |
| [[https://stackoverflow.com/questions/35960883/how-to-unlock-jenkins][Jenkins skip wizzard when initialization]] | -Djenkins.install.runSetupWizard=false |

** Load Jenkins settings via folder copy
| Name | Comment |
Expand All @@ -91,7 +93,7 @@ File me [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/issues][Iss
| [[https://plugins.jenkins.io/jobConfigHistory][JobConfigHistory Plugin]] | Backup job configuration |
| [[https://wiki.jenkins.io/display/JENKINS/Build+User+Vars+Plugin][Build User Vars Plugin]] | Describe the user who started the build |
#+BEGIN_HTML
<a href="https://www.dennyzhang.com"><img align="right" width="185" height="37" src="https://raw.githubusercontent.com/USDevOps/mywechat-slack-group/master/images/dns_small.png"></a>
<a href="https://cheatsheet.dennyzhang.com"><img align="right" width="185" height="37" src="https://raw.githubusercontent.com/dennyzhang/cheatsheet.dennyzhang.com/master/images/cheatsheet_dns.png"></a>
#+END_HTML
** Jenkins Git Via Groovy
| Name | Comment |
Expand Down Expand Up @@ -127,6 +129,8 @@ File me [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/issues][Iss
** Groovy String/Regexp
| Name | Comment |
|--------------------------------+----------------------------------|
| Check string startsWith | =assert s.startsWith("\t")= |
| Trim whitespaces | s=s.trim() |
| [[http://groovy-lang.org/groovy-dev-kit.html#_list_literals][Convert list to string]] | =l.join(";")= |
| Create string with multi-lines | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/multi-line-string.groovy][multi-line-string.groovy]] |
| Convert string to list | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/split-string.groovy][split-string.groovy]] |
Expand Down Expand Up @@ -161,7 +165,7 @@ File me [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/issues][Iss
| Convert dictionary to json | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/dict-to-json.groovy][dict-to-json.groovy]] |
| Read and write json files | [[https://github.com/dennyzhang/cheatsheet-jenkins-groovy-A4/blob/master/json-file.groovy][json-file.groovy]] |
#+BEGIN_HTML
<a href="https://www.dennyzhang.com"><img align="right" width="185" height="37" src="https://raw.githubusercontent.com/USDevOps/mywechat-slack-group/master/images/dns_small.png"></a>
<a href="https://cheatsheet.dennyzhang.com"><img align="right" width="185" height="37" src="https://raw.githubusercontent.com/dennyzhang/cheatsheet.dennyzhang.com/master/images/cheatsheet_dns.png"></a>
#+END_HTML
** Groovy Date
| Name | Comment |
Expand All @@ -188,8 +192,8 @@ https://github.com/fabric8io/jenkins-docker

License: Code is licensed under [[https://www.dennyzhang.com/wp-content/mit_license.txt][MIT License]].
#+BEGIN_HTML
<a href="https://www.dennyzhang.com"><img align="right" width="201" height="268" src="https://raw.githubusercontent.com/USDevOps/mywechat-slack-group/master/images/denny_201706.png"></a>
<a href="https://www.dennyzhang.com"><img align="right" src="https://raw.githubusercontent.com/USDevOps/mywechat-slack-group/master/images/dns_small.png"></a>
<a href="https://cheatsheet.dennyzhang.com"><img align="right" width="201" height="268" src="https://raw.githubusercontent.com/USDevOps/mywechat-slack-group/master/images/denny_201706.png"></a>
<a href="https://cheatsheet.dennyzhang.com"><img align="right" src="https://raw.githubusercontent.com/dennyzhang/cheatsheet.dennyzhang.com/master/images/cheatsheet_dns.png"></a>

<a href="https://www.linkedin.com/in/dennyzhang001"><img align="bottom" src="https://www.dennyzhang.com/wp-content/uploads/sns/linkedin.png" alt="linkedin" /></a>
<a href="https://github.com/dennyzhang"><img align="bottom"src="https://www.dennyzhang.com/wp-content/uploads/sns/github.png" alt="github" /></a>
Expand Down Expand Up @@ -1179,3 +1183,8 @@ pipelineUtils = load "${JENKINS_HOME}/init.groovy.d/pipeline-utils.groovy"
script {
pipelineUtils.sendSlackNotification(slack_target, jobLogs, downstreamJobResult)
}
* HALF Jenkins pipeline check website availability issue :noexport:
https://stackoverflow.com/questions/40393557/jenkins-pipeline-script-to-check-the-website-is-up
https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.triggers.MultibranchWorkflowTriggerContext.urlTrigger


Binary file modified cheatsheet-jenkins-groovy-A4.pdf
Binary file not shown.
17 changes: 16 additions & 1 deletion jenkins-url.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4
// --
// Created : <2018-04-20>
// Updated: Time-stamp: <2019-05-01 16:52:52>
// Updated: Time-stamp: <2019-05-09 11:43:15>
//-------------------------------------------------------------------
// https://gist.github.com/fishi0x01/7c2d29afbaa0f16126eb4d4b35942f76
/*
Expand All @@ -21,3 +21,18 @@ import jenkins.model.JenkinsLocationConfiguration
JenkinsLocationConfiguration location = Jenkins.instance.getExtensionList('jenkins.model.JenkinsLocationConfiguration')[0]
location.url = 'https://jenkins-as-code-poc.devtail.io/'
location.save()

// Solution 2
// https://github.com/docksal/service-jenkins/blob/master/groovy/default-config.groovy
import jenkins.model.*
import hudson.security.*

// Get environment variables.
def env = System.getenv()

// Change location configuration for admin address and Jenkins URL.
// Currently this will override settings changed via Jenkins UI.
def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get()
jenkinsLocationConfiguration.setAdminAddress(env.JENKINS_EMAIL)
jenkinsLocationConfiguration.setUrl(env.JENKINS_URL)
jenkinsLocationConfiguration.save()

0 comments on commit af9fa48

Please sign in to comment.