diff --git a/get-env.groovy b/get-env.groovy index 19d2713..7090cbb 100644 --- a/get-env.groovy +++ b/get-env.groovy @@ -1,4 +1,16 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: get-env.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 // https://stackoverflow.com/questions/31707667/how-to-access-jenkins-environment-variables-with-dsl +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:57> +//------------------------------------------------------------------- def envVars = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars() println envVars['myVar'] diff --git a/get-ip-by-hostname.groovy b/get-ip-by-hostname.groovy index 30732de..d8c4e71 100644 --- a/get-ip-by-hostname.groovy +++ b/get-ip-by-hostname.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: get-ip-by-hostname.groovy +// Author : Denny // https://asoftwareguy.com/2014/04/17/get-the-ip-address-for-a-host-name-in-groovy/ +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:40> +//------------------------------------------------------------------- def hostname = 'google.com' println InetAddress.getByName(hostname).address.collect { it & 0xFF }.join('.') diff --git a/jenkins-views.groovy b/jenkins-views.groovy index 795a502..9431feb 100755 --- a/jenkins-views.groovy +++ b/jenkins-views.groovy @@ -1,5 +1,16 @@ #!groovy - +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: jenkins-views.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:03:51> +//------------------------------------------------------------------- // imports import jenkins.model.Jenkins import hudson.model.ListView diff --git a/jenkinsfile-finally.groovy b/jenkinsfile-finally.groovy index 9ede26c..5d0610b 100644 --- a/jenkinsfile-finally.groovy +++ b/jenkinsfile-finally.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: jenkinsfile-finally.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:05:07> +//------------------------------------------------------------------- node { try { def seconds = readFile("/tmp/test.txt") @@ -17,4 +29,4 @@ node { finally { echo "finally" } -} \ No newline at end of file +} diff --git a/jenkinsfile-parallelly.groovy b/jenkinsfile-parallelly.groovy index 837a5bf..0d85782 100644 --- a/jenkinsfile-parallelly.groovy +++ b/jenkinsfile-parallelly.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: jenkinsfile-parallelly.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:26> +//------------------------------------------------------------------- stage('stage1') { echo 'Hello World' } diff --git a/jenkinsfile-pass-parameter.groovy b/jenkinsfile-pass-parameter.groovy index 63c563b..7b9796c 100644 --- a/jenkinsfile-pass-parameter.groovy +++ b/jenkinsfile-pass-parameter.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: jenkinsfile-pass-parameter.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:05:21> +//------------------------------------------------------------------- node { def seconds = readFile("/tmp/test.txt") diff --git a/jenkinsfile-sequentially b/jenkinsfile-sequentially deleted file mode 100644 index 6748f99..0000000 --- a/jenkinsfile-sequentially +++ /dev/null @@ -1,12 +0,0 @@ -stage('stage1') { - echo 'Hello World' -} - - -stage('stage2') { - build 'dennyjob1' -} - -stage('stage3') { - build job: 'dennyjob2', parameters: [string(name: 'env1', value: 'value3')] -} \ No newline at end of file diff --git a/jenkinsfile-sequentially.groovy b/jenkinsfile-sequentially.groovy index 6748f99..377c0a2 100644 --- a/jenkinsfile-sequentially.groovy +++ b/jenkinsfile-sequentially.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: jenkinsfile-sequentially.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:36> +//------------------------------------------------------------------- stage('stage1') { echo 'Hello World' } @@ -9,4 +21,4 @@ stage('stage2') { stage('stage3') { build job: 'dennyjob2', parameters: [string(name: 'env1', value: 'value3')] -} \ No newline at end of file +} diff --git a/jenkinsfile-timeout-retry.groovy b/jenkinsfile-timeout-retry.groovy index b5d6a9b..b451aa4 100644 --- a/jenkinsfile-timeout-retry.groovy +++ b/jenkinsfile-timeout-retry.groovy @@ -1,5 +1,16 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: jenkinsfile-timeout-retry.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 // https://jenkins.io/doc/pipeline/tour/running-multiple-steps/ - +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:05:16> +//------------------------------------------------------------------- Jenkinsfile (Declarative Pipeline) pipeline { agent any @@ -16,4 +27,4 @@ pipeline { } } } -} \ No newline at end of file +} diff --git a/keep-going-with-errors.groovy b/keep-going-with-errors.groovy index e734c4a..53f94fb 100644 --- a/keep-going-with-errors.groovy +++ b/keep-going-with-errors.groovy @@ -7,11 +7,11 @@ // Author : Denny // Description : // https://stackoverflow.com/questions/36852310/show-a-jenkins-pipeline-stage-as-failed-without-failing-the-whole-job +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 // -- // Created : <2018-04-20> -// Updated: Time-stamp: <2019-02-16 21:47:16> +// Updated: Time-stamp: <2019-02-16 22:04:13> //------------------------------------------------------------------- -//////////////////////////////////////////////////////////////////////////////// // Stages with shell commands def tc_list = testsuites.tokenize(',') tc_list.each { diff --git a/loop-map.groovy b/loop-map.groovy index 7ead07a..ee62aaa 100644 --- a/loop-map.groovy +++ b/loop-map.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: loop-map.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:45> +//------------------------------------------------------------------- def sampleMap = ['Key#1':'Value#1', 'Key#2':'Value#2'] println sampleMap['Key#1'] node{ diff --git a/multi-line-string.groovy b/multi-line-string.groovy index 65f1ac6..62d16f6 100644 --- a/multi-line-string.groovy +++ b/multi-line-string.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: multi-line-string.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:50> +//------------------------------------------------------------------- // http://grails.asia/groovy-multiline-string def a = """test test diff --git a/print.groovy b/print.groovy index 5da33ff..76855e5 100644 --- a/print.groovy +++ b/print.groovy @@ -1,2 +1,14 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: print.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:05:02> +//------------------------------------------------------------------- String message = 'Hello from Groovy' -println message \ No newline at end of file +println message diff --git a/slack-notification.groovy b/slack-notification.groovy index fc50d8e..25fac8c 100644 --- a/slack-notification.groovy +++ b/slack-notification.groovy @@ -9,9 +9,10 @@ // https://stackoverflow.com/questions/39140191/how-to-send-slack-notification-after-jenkins-pipeline-build-failed // https://jenkins.io/doc/pipeline/steps/slack/ // https://jenkins.io/blog/2016/07/18/pipeline-notifications/ +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 // -- // Created : <2018-04-20> -// Updated: Time-stamp: <2019-02-16 21:47:20> +// Updated: Time-stamp: <2019-02-16 22:01:54> //------------------------------------------------------------------- node(agent_label) { diff --git a/split-string.groovy b/split-string.groovy index 74a9703..fd42827 100644 --- a/split-string.groovy +++ b/split-string.groovy @@ -1,3 +1,15 @@ +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: split-string.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:19> +//------------------------------------------------------------------- String ip_hostname_list = """ 138.197.192.172 myenv-do-jenkins 138.68.254.56 myenv-do-lb-1 138.68.254.215 myenv-do-lb-2 diff --git a/timezone.groovy b/timezone.groovy old mode 100644 new mode 100755 index b716b36..286dcda --- a/timezone.groovy +++ b/timezone.groovy @@ -1,3 +1,16 @@ +#!groovy +//------------------------------------------------------------------- +// @copyright 2018 DennyZhang.com +// Licensed under MIT +// https://www.dennyzhang.com/wp-content/mit_license.txt +// +// File: timezone.groovy +// Author : Denny +// Link: https://cheatsheet.dennyzhang.com/cheatsheet-jenkins-groovy-a4 +// -- +// Created : <2018-04-20> +// Updated: Time-stamp: <2019-02-16 22:04:03> +//------------------------------------------------------------------- // Configure Jenkins java options // timezone: Asia/Shanghai, America/New_York, America/Los_Angeles // https://www.epochconverter.com/timezones