xavieryang 修订了这个 Gist . 跳至此修订
1 file changed, 7 insertions, 7 deletions
snippetsJenkins.groovy
| @@ -76,11 +76,11 @@ if (userId) { | |||
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | 78 | // Check if branch exists on remote | |
| 79 | - | def branchCheckOutput = bat( | |
| 80 | - | script: "git ls-remote --heads origin ${env.JENKINS_UPLOAD_LABEL}", | |
| 81 | - | returnStdout: true | |
| 82 | - | ).trim() | |
| 79 | + | def branchCheckOutput = bat( | |
| 80 | + | script: "git ls-remote --heads origin ${env.JENKINS_UPLOAD_LABEL}", | |
| 81 | + | returnStdout: true | |
| 82 | + | ).trim() | |
| 83 | 83 | ||
| 84 | - | if (branchCheckOutput =~ /refs\/heads\/${env.JENKINS_UPLOAD_LABEL}/) { | |
| 85 | - | error "Branch ${env.JENKINS_UPLOAD_LABEL} already exists on remote." | |
| 86 | - | } | |
| 84 | + | if (branchCheckOutput =~ /refs\/heads\/${env.JENKINS_UPLOAD_LABEL}/) { | |
| 85 | + | error "Branch ${env.JENKINS_UPLOAD_LABEL} already exists on remote." | |
| 86 | + | } | |
xavieryang 修订了这个 Gist . 跳至此修订
1 file changed, 12 insertions, 1 deletion
snippetsJenkins.groovy
| @@ -72,4 +72,15 @@ def userId = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)?.get | |||
| 72 | 72 | if (userId) { | |
| 73 | 73 | def user = User.get(userId) | |
| 74 | 74 | env.user_email = user.getProperty(hudson.tasks.Mailer.UserProperty)?.getAddress() | |
| 75 | - | } | |
| 75 | + | } | |
| 76 | + | ||
| 77 | + | ||
| 78 | + | // Check if branch exists on remote | |
| 79 | + | def branchCheckOutput = bat( | |
| 80 | + | script: "git ls-remote --heads origin ${env.JENKINS_UPLOAD_LABEL}", | |
| 81 | + | returnStdout: true | |
| 82 | + | ).trim() | |
| 83 | + | ||
| 84 | + | if (branchCheckOutput =~ /refs\/heads\/${env.JENKINS_UPLOAD_LABEL}/) { | |
| 85 | + | error "Branch ${env.JENKINS_UPLOAD_LABEL} already exists on remote." | |
| 86 | + | } | |
xavieryang 修订了这个 Gist . 跳至此修订
1 file changed, 9 insertions, 1 deletion
snippetsJenkins.groovy
| @@ -64,4 +64,12 @@ properties([parameters([ | |||
| 64 | 64 | ] | |
| 65 | 65 | ] | |
| 66 | 66 | ] | |
| 67 | - | ])]) | |
| 67 | + | ])]) | |
| 68 | + | ||
| 69 | + | // send mail to the executor of job (LDAP) | |
| 70 | + | import hudson.model.User | |
| 71 | + | def userId = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)?.getUserId() | |
| 72 | + | if (userId) { | |
| 73 | + | def user = User.get(userId) | |
| 74 | + | env.user_email = user.getProperty(hudson.tasks.Mailer.UserProperty)?.getAddress() | |
| 75 | + | } | |
xavieryang 修订了这个 Gist . 跳至此修订
1 file changed, 0 insertions, 0 deletions
activeChoiceJenkins.groovy 重命名为 snippetsJenkins.groovy
File renamed without changes
xavieryang 修订了这个 Gist . 跳至此修订
1 file changed, 67 insertions
activeChoiceJenkins.groovy(file created)
| @@ -0,0 +1,67 @@ | |||
| 1 | + | // Parameterize agent label | |
| 2 | + | if (params.containsKey('AGENT_LABEL')) { | |
| 3 | + | AGENT_LABEL = "$params.AGENT_LABEL" | |
| 4 | + | } | |
| 5 | + | pipeline { | |
| 6 | + | agent { label "${AGENT_LABEL}" } | |
| 7 | + | parameters { | |
| 8 | + | string(name: 'AGENT_LABEL', defaultValue: 'labelA') | |
| 9 | + | } | |
| 10 | + | } | |
| 11 | + | ||
| 12 | + | // Substitute pipeline environment variable in shared library code (environment{} block does not work) | |
| 13 | + | withEnv(["ENV_ABC=123"]) { | |
| 14 | + | script { | |
| 15 | + | output = lib.function() | |
| 16 | + | echo "output: ${output}" | |
| 17 | + | } | |
| 18 | + | } | |
| 19 | + | // In shared library | |
| 20 | + | String function() { | |
| 21 | + | return "${ENV_ABC}" | |
| 22 | + | } | |
| 23 | + | ||
| 24 | + | // Set variable from sh stdout (full and last word) | |
| 25 | + | // note: returnStdout removes the output from jenkins build console log, have to explicitly echo it | |
| 26 | + | script { | |
| 27 | + | stdout_full = sh ( | |
| 28 | + | script: "ls -ltr", | |
| 29 | + | returnStdout: true | |
| 30 | + | ).trim() | |
| 31 | + | echo "${stdout_full}" | |
| 32 | + | stdout_last = full_stdout.tokenize().last() | |
| 33 | + | echo "${stdout_last}" | |
| 34 | + | } | |
| 35 | + | ||
| 36 | + | // Active choice (plugin) parameters with dynamic editable user input | |
| 37 | + | // outside pipeline{} block | |
| 38 | + | properties([parameters([ | |
| 39 | + | [$class: 'DynamicReferenceParameter', | |
| 40 | + | choiceType: 'ET_FORMATTED_HTML', | |
| 41 | + | omitValueField: true, | |
| 42 | + | description: 'Editable field when PARENT_PARAM is Others', | |
| 43 | + | name: 'ACTIVE_PARAM', | |
| 44 | + | randomName: 'choice-parameter-5631314456178624', | |
| 45 | + | referencedParameters: 'PARENT_PARAM', | |
| 46 | + | script: [ | |
| 47 | + | $class: 'GroovyScript', | |
| 48 | + | fallbackScript: [ | |
| 49 | + | classpath: [], | |
| 50 | + | sandbox: true, | |
| 51 | + | script: "return['undefined']" | |
| 52 | + | ], | |
| 53 | + | script: [ | |
| 54 | + | classpath: [], | |
| 55 | + | sandbox: true, | |
| 56 | + | script: | |
| 57 | + | """ | |
| 58 | + | if(PARENT_PARAM.equals('Others')) { | |
| 59 | + | inputBox="<input class='setting-input' name='value' type='text' value=''>" | |
| 60 | + | } else { | |
| 61 | + | inputBox="<input class='setting-input' name='value' type='hidden' value=''>" | |
| 62 | + | } | |
| 63 | + | """ | |
| 64 | + | ] | |
| 65 | + | ] | |
| 66 | + | ] | |
| 67 | + | ])]) | |