├── .gitignore
├── README.md
├── examples
├── README.md
├── TAP_docker_image_build_push_ecr
│ ├── Dockerfile
│ └── Jenkinsfile
├── TAP_docker_image_pull_ecr
│ └── Jenkinsfile
└── TAP_generic_python_runner
│ ├── Dockerfile
│ └── Jenkinsfile
├── pom.xml
├── resources
└── images
│ ├── TAP-small.png
│ └── TAP.png
├── src
├── TAP_basic_flow_settings.groovy
├── com
│ └── tikalk
│ │ ├── ci
│ │ ├── BasePipeline.groovy
│ │ ├── gradle
│ │ │ ├── GradlePipeline.groovy
│ │ │ └── GradlePipelineScript.groovy
│ │ └── maven
│ │ │ ├── ArtifactoryPipeline.groovy
│ │ │ └── ArtifactoryPipelineScript.groovy
│ │ ├── notifyBuild.groovy
│ │ └── utils
│ │ ├── Library.groovy
│ │ └── Logger.groovy
└── settings_mail.groovy
├── test
├── pipelines
│ ├── BASIC-CI-FLOW-DEMO
│ │ ├── declarative
│ │ │ └── Jenkinsfile
│ │ └── scripted
│ │ │ └── Jenkinsfile
│ ├── The_Force_Awakens
│ │ ├── declarative
│ │ │ └── Jenkinsfile
│ │ └── scripted
│ │ │ └── Jenkinsfile
│ ├── advanced_slack_notification
│ │ └── Jenkinsfile
│ ├── echo_test
│ │ └── Jenkinsfile
│ └── email_flow
│ │ └── Jenkinsfile
└── python
│ └── generic_python_runner
│ ├── requirements.txt
│ └── simple.py
└── vars
├── README.md
├── TAP_advancedSlackNotification.groovy
├── TAP_echo.groovy
├── TAP_email.groovy
├── TAP_getBuildUserId.groovy
└── TAP_setStatusByLogText.groovy
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
14 | .idea/
15 | *.iml
16 | target/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # TAP - tikal-advanced-pipeline
3 | ***Advanced Jenkins Pipeline library***.
4 |
5 | Powered by **[Tikal Knowledge](http://www.tikalk.com)** and the community.
6 |
7 |
8 | Tikal Advanced Pipeline is a [shared library](https://jenkins.io/doc/book/pipeline/shared-libraries/) for [Jenkins Pipeline](https://jenkins.io/doc/book/pipeline/).
9 |
10 | The Library is a collection of tasks and examples that can be used inside a pipeline.
11 |
12 | Anyone who wants to contribute to this library - please follow the instructions below in the page.
13 |
14 | ## [Available tasks](vars/README.md)
15 |
16 | * TAP_advancedSlackNotification
17 | * TAP_echo
18 | * TAP_email
19 | * TAP_getBuildUserId
20 | * TAP_setStatusByLogText
21 |
22 | ## [Available examples](examples/README.md)
23 |
24 | * Build a Docker image and push it to ECR
25 | * Pull Docker image from ECR
26 |
27 | ## Adding an item to tikal-advanced-pipeline
28 |
29 | For adding a new task or an example, please follow those steps.
30 |
31 | 1. Create a branch or a fork from the master branch.
32 | 2. Write the groovy/Jenkinsfile file for the task/example (along with matching src and resources files if needed) - the file name **MUST** start with **TAP_** prefix.
33 | 3. If it is a task, write a test Jenkinsfile for testing the new task and place it in a separate folder in **'/test/pipelines'** folder.
34 | 4. Write a markdown section for describing the added item in the matching README.md file.
35 | 6. Submit a pull request.
36 |
37 | Please notice that only the following of all those steps will be accepted.
38 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # ***tikal-Advanced-Pipeline examples***
3 |
4 | Powered by **[Tikal Knowledge](http://www.tikalk.com)** and the community.
5 |
6 |
7 | # TAP_docker_image_build_push_ecr
8 |
9 | ***This example shows how to build a Docker image and push it to Amazon ECR***
10 |
11 | [TAP_docker_image_build_push_ecr example](TAP_docker_image_build_push_ecr/Jenkinsfile)
12 |
13 | # TAP_docker_image_pull_ecr
14 |
15 | ***This example shows how to pull a Docker image from Amazon ECR***
16 |
17 | [TAP_docker_image_pull_ecr example](TAP_docker_image_pull_ecr/Jenkinsfile)
18 |
19 | # TAP_generic_python_runner
20 |
21 | ***This pipeline is a generic Python script runner***
22 |
23 | [TAP_generic_python_runner](TAP_generic_python_runner/Jenkinsfile)
24 |
25 |
--------------------------------------------------------------------------------
/examples/TAP_docker_image_build_push_ecr/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:2
2 |
3 | CMD ["/bin/true"]
4 |
--------------------------------------------------------------------------------
/examples/TAP_docker_image_build_push_ecr/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline
2 | {
3 | options
4 | {
5 | buildDiscarder(logRotator(numToKeepStr: '3'))
6 | }
7 | agent any
8 | environment
9 | {
10 | VERSION = 'latest'
11 | PROJECT = 'tap_sample'
12 | IMAGE = 'tap_sample:latest'
13 | ECRURL = 'http://999999999999.dkr.ecr.eu-central-1.amazonaws.com'
14 | ECRCRED = 'ecr:eu-central-1:tap_ecr'
15 | }
16 | stages
17 | {
18 | stage('Build preparations')
19 | {
20 | steps
21 | {
22 | script
23 | {
24 | // calculate GIT lastest commit short-hash
25 | gitCommitHash = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
26 | shortCommitHash = gitCommitHash.take(7)
27 | // calculate a sample version tag
28 | VERSION = shortCommitHash
29 | // set the build display name
30 | currentBuild.displayName = "#${BUILD_ID}-${VERSION}"
31 | IMAGE = "$PROJECT:$VERSION"
32 | }
33 | }
34 | }
35 | stage('Docker build')
36 | {
37 | steps
38 | {
39 | script
40 | {
41 | // Build the docker image using a Dockerfile
42 | docker.build("$IMAGE","examples/TAP_docker_image_build_push_ecr")
43 | }
44 | }
45 | }
46 | stage('Docker push')
47 | {
48 | steps
49 | {
50 | script
51 | {
52 | // login to ECR - for now it seems that that the ECR Jenkins plugin is not performing the login as expected. I hope it will in the future.
53 | sh("eval \$(aws ecr get-login --no-include-email | sed 's|https://||')")
54 | // Push the Docker image to ECR
55 | docker.withRegistry(ECRURL, ECRCRED)
56 | {
57 | docker.image(IMAGE).push()
58 | }
59 | }
60 | }
61 | }
62 | }
63 |
64 | post
65 | {
66 | always
67 | {
68 | // make sure that the Docker image is removed
69 | sh "docker rmi $IMAGE | true"
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/examples/TAP_docker_image_pull_ecr/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline
2 | {
3 | options
4 | {
5 | buildDiscarder(logRotator(numToKeepStr: '3'))
6 | }
7 |
8 | agent any
9 | environment
10 | {
11 | PROJECT = 'tap_sample'
12 | ECRURL = 'http://999999999999.dkr.ecr.eu-central-1.amazonaws.com'
13 | ECRCRED = 'ecr:eu-central-1:tap_ecr'
14 | }
15 | stages
16 | {
17 | stage('Docker image pull')
18 | {
19 | steps
20 | {
21 | script
22 | {
23 | sh("eval \$(aws ecr get-login --no-include-email | sed 's|https://||')")
24 | docker.withRegistry(ECRURL, ECRCRED)
25 | {
26 | docker.image(PROJECT).pull()
27 | }
28 | }
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/examples/TAP_generic_python_runner/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:2.7
2 |
3 | # install some generic Python modules
4 | RUN pip install ansible==2.3
5 | RUN pip install boto==2.46.1
6 | RUN pip install credstash==1.13.2
7 | RUN pip install fasteners==0.14.1
8 | RUN pip install futures==3.0.5
9 | RUN pip install pyfscache==0.9.12
10 | RUN pip install PyYAML==3.12
11 | RUN pip install hvac==0.2.17
12 | RUN pip install awscli==1.11.70
13 | RUN pip install docker==2.5.1
14 |
15 | # install docker client
16 | RUN apt-get update && \
17 | apt-get install -y apt-transport-https ca-certificates curl software-properties-common && \
18 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
19 | add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable" && \
20 | apt-get update && \
21 | apt-get install -y docker-ce
22 |
--------------------------------------------------------------------------------
/examples/TAP_generic_python_runner/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline
2 | {
3 | parameters
4 | {
5 | string(name: 'REPOSITORY_URL', defaultValue: '', description: '
* URL to GIT repository')
6 | string(name: 'GIT_REPO_CRED', defaultValue: '', description: '
* Credential name of GIT user')
7 | string(name: 'BRANCH', defaultValue: 'master', description: '
Name of branch (default: master)')
8 | string(name: 'REQUIREMENTS_FILE', description: '
Relative path to the requirements file')
9 | string(name: 'PYTHON_SCRIPT_FILE', description: '
* Relative path to the python script')
10 | text(name: 'GROOVY_SCRIPT', defaultValue: '', description: '
Insert a groovy script text to run.
e.g.:
env.PARAM1="value1"
env.PARAM2="value2"')
11 | }
12 |
13 | options
14 | {
15 | buildDiscarder(logRotator(numToKeepStr: '100', daysToKeepStr: '45'))
16 | ansiColor('xterm')
17 | timestamps()
18 | }
19 |
20 | agent
21 | {
22 | dockerfile
23 | {
24 | filename 'examples/TAP_generic_python_runner/Dockerfile'
25 | args "-u root -v /var/run/docker.sock:/var/run/docker.sock"
26 | }
27 | }
28 |
29 | stages
30 | {
31 | stage('Setup')
32 | {
33 | steps
34 | {
35 | script
36 | {
37 | def script = PYTHON_SCRIPT_FILE.tokenize('/')[-1]
38 | currentBuild.displayName = "#${BUILD_ID} | ${script}"
39 | }
40 | checkout([
41 | $class : 'GitSCM', branches: [[name: BRANCH]],
42 | userRemoteConfigs: [[url: "${REPOSITORY_URL}", credentialsId: "${GIT_REPO_CRED}"]]
43 | ])
44 | }
45 | }
46 |
47 | stage('Install requirements')
48 | {
49 | steps
50 | {
51 | sh '''
52 | if [ "x${REQUIREMENTS_FILE}" != "x" ] && [ -f ${REQUIREMENTS_FILE} ]; then
53 | pip install -r ${REQUIREMENTS_FILE};
54 | fi
55 | '''
56 | }
57 | }
58 | stage('Run script')
59 | {
60 | steps
61 | {
62 | script
63 | {
64 | writeFile encoding: 'UTF-8',file: './variables.groovy', text: GROOVY_SCRIPT
65 | load './variables.groovy'
66 | sh "ls -la /var/run/docker.sock"
67 | sh "python ./${PYTHON_SCRIPT_FILE}"
68 | }
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
9 | 4.0.0
10 |
11 | org.tikalk
12 | pipeline
13 | Pipeline CI Utils
14 | 1.0-SNAPSHOT
15 |
16 |
17 |
18 | repo.jenkins-ci.org
19 | http://repo.jenkins-ci.org/public/
20 |
21 |
22 |
23 |
24 |
25 | org.codehaus.groovy
26 | groovy-all
27 | 2.4.7
28 |
29 |
30 | com.cloudbees
31 | groovy-cps
32 | 1.11
33 | provided
34 |
35 |
36 | junit
37 | junit
38 | 4.12
39 | test
40 |
41 |
42 | org.jenkins-ci.plugins
43 | artifactory
44 | 2.12.1
45 |
46 |
47 |
48 |
49 | src
50 |
51 |
52 |
53 | org.codehaus.gmavenplus
54 | gmavenplus-plugin
55 | 1.5
56 |
57 |
58 |
59 | addSources
60 | addTestSources
61 | compile
62 | testCompile
63 |
64 |
65 |
66 |
67 |
68 |
69 | ${project.basedir}/src
70 |
71 | **/*.groovy
72 |
73 |
74 |
75 |
76 |
77 | ${project.basedir}/test
78 |
79 | **/*.groovy
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/resources/images/TAP-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tikalk/tikal-advanced-pipeline/495b932430efc6a5d89a25d77bf10e4b02b4cf38/resources/images/TAP-small.png
--------------------------------------------------------------------------------
/resources/images/TAP.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tikalk/tikal-advanced-pipeline/495b932430efc6a5d89a25d77bf10e4b02b4cf38/resources/images/TAP.png
--------------------------------------------------------------------------------
/src/TAP_basic_flow_settings.groovy:
--------------------------------------------------------------------------------
1 | class TAP_basic_flow_settings implements Serializable {
2 | private String flow
3 | private String gitUrl
4 |
5 | def setFlow(value) {
6 | flow = value
7 | }
8 | def getFlow() {
9 | flow
10 | }
11 | def setGitUrl(value) {
12 | gitUrl = value
13 | }
14 | def getGitUrl() {
15 | gitUrl
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/com/tikalk/ci/BasePipeline.groovy:
--------------------------------------------------------------------------------
1 | package com.tikalk.ci;
2 |
3 | import com.tikalk.utils.Logger
4 | import com.cloudbees.groovy.cps.NonCPS
5 |
6 | abstract class BasePipeline implements Serializable {
7 |
8 | def logger
9 | def script
10 | def gitBranch
11 | def gitCredentialsId
12 | def gitRepoUrl
13 | def firstUnstableStage
14 | def pauseAfterEachStage
15 |
16 | BasePipeline(script) {
17 | this.script = script
18 |
19 | logger = new Logger(script)
20 | }
21 |
22 | void run() {
23 | script.timestamps() {
24 | try {
25 | script.echo "Running with params: ${this.properties}"
26 | runImpl()
27 | } finally {
28 | try {
29 | if (pauseAfterEachStage) {
30 | script.timeout(time: 180, unit: 'MINUTES') {
31 | script.input 'Continue to next stage?'
32 | }
33 | }
34 | archiveServiceLogs()
35 | cleanupResources()
36 | deleteWorkspace()
37 | if (firstUnstableStage) {
38 | script.echo "Build became UNSTABLE in stage $firstUnstableStage"
39 | }
40 | } catch (all) {
41 | logger.info "Issue during cleanup: $all. This can hide real issue that happened in the steps, check what step actually failed"
42 | }
43 |
44 | }
45 | }
46 | }
47 |
48 | void runStage(String name, Closure stage) {
49 | if (currentBuildResult in ['SUCCESS', null]) {
50 | script.echo "Start stage $name"
51 | script.stage(name, stage)
52 | script.echo "End stage $name with result ${currentBuildResult ?: 'SUCCESS'}"
53 | } else {
54 | script.stage(name) {
55 | script.echo "Build is unstable, skipping stage $name"
56 | this.firstUnstableStage = firstUnstableStage ?: name
57 | }
58 | }
59 | if (pauseAfterEachStage) {
60 | script.timeout(time: 180, unit: 'MINUTES') {
61 | script.input 'Continue to next stage?'
62 | }
63 | }
64 | }
65 |
66 | void runImpl() {
67 | runStage('Setup', this.&setup)
68 | runStage('Checkout', this.&checkout)
69 | runStage('Build', this.&build)
70 | runStage('Upload Artifact', this.&uploadArtifact)
71 | runStage('Prepare Test Env', this.&prepareTestEnv)
72 | runStage('System Tests', this.&systemTests)
73 | runStage('Deploy', this.&deploy)
74 |
75 | }
76 |
77 | void setup() {
78 | initParams()
79 | populateBuildInfo()
80 | setGitConfig()
81 | }
82 |
83 | void initParams() {
84 | gitCredentialsId = script.params.gitCredentialsId //script.params.// Implement to set params that are not able to set in constructor (due to @NonCPS etc)
85 | gitRepoUrl = script.params.gitRepoUrl
86 | }
87 |
88 | void populateBuildInfo() {
89 | // populateBuildDisplayName()
90 | // populateBuildDescription()
91 | }
92 |
93 | void populateBuildDisplayName() {
94 | script.currentBuild.displayName = "" //"""${script.currentBuild.displayName} ${gitBranch ?: ''}"
95 | }
96 |
97 | void populateBuildDescription() {
98 | // Set public IP as description, if found
99 | def description = "Need the slave ip"
100 | script.currentBuild.description = description
101 |
102 | }
103 |
104 | void deploy(){
105 | logger.info "Implements deploy logic here (push to docker , maven, gradle deploy)"
106 | }
107 |
108 | void uploadArtifact(){
109 | logger.info "Implements uploading artifacts to various repositories (push to docker , maven, gradle deploy)"
110 | }
111 |
112 | void setGitConfig() {
113 | script.sh '''git --version
114 | git config --global push.default simple
115 | git config --global user.email "aaa"
116 | git config --global user.name "bbb"
117 | '''
118 | }
119 |
120 | void checkout() {
121 | script.git credentialsId: gitCredentialsId, url: gitRepoUrl
122 |
123 | }
124 |
125 | void gitCheckout(Map m) {
126 | def repository = m.repository
127 | def branch = m.branch ?: 'master'
128 | def targetDir = m.targetDir ?: m.repository
129 |
130 | script.dir("$targetDir") {
131 | // Run git clean and swallow errors which are normal when running first time
132 | script.sh returnStatus: true, script: 'git fetch'
133 | script.git credentialsId: 'jenkins-github-ssh', url: "git@.git", branch: "$branch"
134 | }
135 | }
136 |
137 | void gitCheckoutProject() {
138 | gitCheckout branch: gitBranch, repository: gitRepository
139 | }
140 |
141 | // Rebase the current change over current origin master, so we are running with latest changes
142 | void gitRebaseOntoMaster() {
143 | script.dir(gitRepository) {
144 | script.sh "git fetch && git pull origin $masterBranch"
145 | }
146 | }
147 |
148 | void build() {
149 | }
150 |
151 | void createGitInfoFile() {
152 | // Implement in CIs where info file is not created during compile (i.e. non maven builds
153 | }
154 |
155 | void compile(Map m) {
156 | // Implement in CIs where build is needed
157 | }
158 |
159 | void unitTests() {
160 | // Implement in CIs where UTs are not being run during compile (i.e. non maven builds)
161 | }
162 |
163 | void systemTests() {}
164 |
165 | void prepareTestEnv() {
166 | }
167 |
168 | void waitForService(Map m) {
169 | script.echo "Waiting for ${m.name} to start"
170 | script.timeout(time: m.timeoutSeconds, unit: 'SECONDS') {
171 | script.waitUntil {
172 | try {
173 | script.httpRequest(m.url)
174 | true
175 | } catch (ignored) {
176 | false
177 | }
178 | }
179 | }
180 | script.echo "${m.name} started succesfully"
181 | }
182 |
183 | @NonCPS
184 | static String toPropertiesFile(Map properties) {
185 | properties.findAll { it.value }
186 | .collect { "${it.key}=${it.value}" }
187 | .join('\n')
188 | }
189 |
190 | void runTests() {
191 | runSystemTests()
192 | archiveTestScreenshots()
193 | archiveTestResults()
194 | // Archiving test results can change script.currentBuilt.result
195 |
196 | }
197 |
198 | void runSystemTests() {
199 |
200 | }
201 |
202 | void archiveTestScreenshots() {
203 | }
204 |
205 | void archiveServiceLogs() {
206 | }
207 |
208 | void cleanupResources() {
209 | }
210 |
211 | void deleteWorkspace() {
212 | script.step([$class: 'WsCleanup'])
213 | }
214 |
215 | void archiveTestResults() {
216 | // Publishing testNG results
217 | script.step([$class : 'JUnitResultArchiver', allowEmptyResults: true,
218 | testResults: "**/target/failsafe-reports/junitreports/TEST-*.xml"])
219 | }
220 |
221 | void gitMergeMaster() {
222 | script.echo 'Checkout master and merge the feature branch to it'
223 | script.dir(gitRepository) {
224 | script.sh """
225 | git fetch
226 | git checkout -B $masterBranch origin/$masterBranch
227 | git merge origin/$gitBranch
228 | """
229 | }
230 | }
231 |
232 | void gitPushToMaster() {
233 | script.dir(gitRepository) {
234 | script.sh "git push origin HEAD:${masterBranch ?: 'master'}"
235 | }
236 | }
237 |
238 | void gitDeleteRemoteBranch() {
239 | if (['master', 'stable', 'development'].contains(gitRepository)) {
240 | script.echo "Not deleting $gitRepository since it is protected"
241 | }
242 | script.dir(gitRepository) {
243 | script.sh "git fetch && git push origin --delete $gitBranch"
244 | }
245 | }
246 |
247 | String getCurrentBuildResult() {
248 | return script.currentBuild.result
249 | }
250 | }
251 |
--------------------------------------------------------------------------------
/src/com/tikalk/ci/gradle/GradlePipeline.groovy:
--------------------------------------------------------------------------------
1 | package com.tikalk.ci.gradle;
2 |
3 | import com.tikalk.ci.BasePipeline
4 |
5 | class GradlePipeline extends BasePipeline {
6 | boolean debugMode
7 | int waitForInputTimeout
8 | def buildTarget
9 | def dockerHost
10 | def certPath
11 | def certUrl
12 | def uploadArtifactTarget
13 |
14 |
15 | GradlePipeline(script) {
16 | super(script)
17 | }
18 |
19 |
20 | @Override
21 | void populateBuildDisplayName() {
22 | script.currentBuild.displayName = "${script.currentBuild.displayName} ${retrieveCurrentBuildUser()}"
23 | }
24 |
25 | void retrieveCurrentBuildUser() {
26 | script.wrap([$class: 'BuildUser']) {
27 | script.sh returnStdout: true, script: 'echo ${BUILD_USER}'
28 | }
29 | }
30 |
31 | @Override
32 | void initParams()
33 | {
34 | gitCredentialsId = script.params.gitCredentialsId //script.params.// Implement to set params that are not able to set in constructor (due to @NonCPS etc)
35 | gitRepoUrl = script.params.gitRepoUrl
36 | buildTarget = script.params.buildTarget //script.params.// Implement to set params that are not able to set in constructor (due to @NonCPS etc)
37 | uploadArtifactTarget = script.params.uploadArtifactTarget != null ? script.params.uploadArtifactTarget : 'pushImage'
38 | dockerHost = script.params.dockerHost
39 | certPath = script.params.certPath
40 | certUrl = script.params.certUrl
41 | }
42 |
43 | @Override
44 | void build() {
45 | logger.info "Implements gradle build here"
46 | script.sh "ls"
47 | script.sh "./gradlew $buildTarget -PdockerHost=$dockerHost -PcertUrl=$certUrl -PcertPath=$certPath"
48 | }
49 |
50 | @Override
51 | void uploadArtifact() {
52 | logger.info "Implements gradle build here"
53 | script.sh "ls"
54 | script.sh "./gradlew $uploadArtifactTarget -PdockerHost=$dockerHost -PcertUrl=$certUrl -PcertPath=$certPath"
55 | }
56 |
57 |
58 | void waitForInput() {
59 | script.timeout(time: waitForInputTimeout, unit: 'MINUTES') {
60 | if (debugMode) {
61 | script.input 'Continue with cleanup?'
62 | }
63 | }
64 | }
65 |
66 |
67 |
68 | void compile(Map m) {
69 |
70 | }
71 |
72 | void buildDocker() {
73 |
74 | }
75 |
76 |
77 |
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/com/tikalk/ci/gradle/GradlePipelineScript.groovy:
--------------------------------------------------------------------------------
1 | package com.tikalk.ci.gradle
2 |
3 | import com.tikalk.utils.Library
4 | import com.tikalk.ci.gradle.GradlePipeline
5 |
6 |
7 | @Library('tikal-advanced-pipeline') _
8 |
9 |
10 | node("linux-host-slave") {
11 | pipeline = new GradlePipeline(this)
12 | pipeline.run()
13 |
14 | def buildResult = pipeline.getCurrentBuildResult() != null ? pipeline.getCurrentBuildResult() : 'SUCCESS'
15 | def buildNum = env.BUILD_NUMBER
16 | def buildURL = env.BUILD_URL
17 |
18 | emailext body: 'Your Jenkins Job, Num. ' + buildNum + ' Finished With Status => ' +
19 | buildResult + '\nYou Can Reach The Test Result Page Here. ' +
20 | buildURL + 'cucumber-html-reports/overview-features.html',
21 | subject: 'Build ' + env.BUILD_NUMBER + ' Result',
22 | to: 'itai@tikalk.com'
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/com/tikalk/ci/maven/ArtifactoryPipeline.groovy:
--------------------------------------------------------------------------------
1 | package com.tikalk.ci.maven
2 |
3 | import com.tikalk.ci.BasePipeline
4 | import org.jfrog.hudson.pipeline.dsl.ArtifactoryPipelineGlobal
5 | import org.jfrog.hudson.pipeline.types.MavenDescriptor
6 |
7 | /**
8 | * Created by ccohen on 7/6/17.
9 | */
10 | class ArtifactoryPipeline extends BasePipeline {
11 |
12 | ArtifactoryPipelineGlobal artifactory
13 | // MavenModuleSet moduleSet
14 | def server
15 | def rtMaven
16 | def buildInfo
17 |
18 | def artifactoryName
19 | def mavenName
20 | def snapshotRepo
21 | def releaseRepo
22 | def vSnapshotRepo
23 | def vReleaseRepo
24 |
25 | def gitRepoUrl
26 | def gitCredentialsId
27 |
28 | boolean dryRun = false
29 | boolean release = false
30 | String releaseVersion
31 | String developmentVersion
32 |
33 | ArtifactoryPipeline(script) {
34 | super(script)
35 | artifactory = new ArtifactoryPipelineGlobal(script)
36 |
37 | }
38 |
39 | @Override
40 | void runImpl() {
41 | // super.runImpl()
42 | try {
43 | runStage('Setup', this.&setup)
44 | runStage('Checkout', this.&checkout)
45 |
46 | if (release) {
47 | preRelease()
48 | // doRelease()
49 | }
50 |
51 | runStage('Test', this.&unitTests)
52 | runStage('Install', this.&build)
53 | runStage('Deploy', this.&deploy)
54 |
55 | if (release) {
56 | postRelease()
57 | }
58 |
59 | } catch (e) {
60 | script.currentBuild.result = "FAILURE"
61 | // script.error e.message
62 | throw e
63 | }
64 | finally {
65 | buildNotifier()
66 | }
67 |
68 | }
69 |
70 | @Override
71 | void setup() {
72 | gitConfig()
73 |
74 | server = artifactory.server artifactoryName
75 |
76 | rtMaven = artifactory.newMavenBuild()
77 | rtMaven.tool = mavenName // Tool name from Jenkins configuration
78 | rtMaven.resolver releaseRepo: vReleaseRepo, snapshotRepo: vSnapshotRepo, server: server
79 | rtMaven.deployer releaseRepo: releaseRepo, snapshotRepo: snapshotRepo, server: server
80 | rtMaven.deployer.deployArtifacts = false // Disable artifacts deployment during Maven run
81 |
82 | buildInfo = artifactory.newBuildInfo()
83 | buildInfo.env.capture = true
84 | // automatically capture environment variables while downloading and uploading files
85 | }
86 |
87 | @Override
88 | void checkout() {
89 | script.git credentialsId: gitCredentialsId, url: gitRepoUrl
90 | }
91 |
92 | @Override
93 | void unitTests() {
94 | rtMaven.run pom: 'pom.xml', goals: 'clean test'
95 |
96 | script.junit allowEmptyResults: true, testResults: 'target/surefire-reports/*.xml, target/failsafe-reports/*.xml'
97 | }
98 |
99 | @Override
100 | void build() {
101 | rtMaven.run pom: 'pom.xml', goals: 'install', buildInfo: buildInfo
102 | }
103 |
104 | @Override
105 | void deploy() {
106 | buildInfo.env.collect() // collect environment variables
107 | buildInfo.retention maxBuilds: 10, maxDays: 7, deleteBuildArtifacts: true
108 | rtMaven.deployer.deployArtifacts buildInfo
109 | server.publishBuildInfo buildInfo
110 |
111 | script.archive "target/**/*"
112 | }
113 |
114 | void doRelease() {
115 | def version = computeReleaseVersion()
116 | // script.sh '''
117 | // eval `ssh-agent -s`
118 | // ssh-add '''
119 |
120 | // script.steps.step.sshagent([gitCredentialsId]) {
121 | // rtMaven.run pom: 'pom.xml', goals: '-Dresume=false release:prepare release:perform'
122 | // }
123 |
124 | }
125 |
126 | void preRelease() {
127 | // omit '-SNAPSHOT'
128 | // def version = computeReleaseVersion()
129 | def version = releaseVersion
130 | logger.info 'prepare to release version: ' + version
131 |
132 | script.pom = script.readMavenPom file: 'pom.xml'
133 | MavenDescriptor descriptor = artifactory.mavenDescriptor()
134 | descriptor.setVersion(version)
135 | descriptor.setFailOnSnapshot(true)
136 | descriptor.transform()
137 |
138 | computeScmTag(script.pom.artifactId + '-' + version)
139 |
140 | script.sh "git commit -am 'prepare release ${script.pom.artifactId}-$version'"
141 | }
142 |
143 | void gitConfig() {
144 | /*
145 | script.sh '''
146 | git config user.name Jenkins
147 | git config user.email nobody@domain.com'''
148 | */
149 | }
150 |
151 | void gitCommit() {
152 |
153 | }
154 |
155 | void postRelease() {
156 | // set version to next version + '-SNAPSHOT'
157 | // def version = computeNextVersion()
158 | def version = developmentVersion
159 | logger.info 'set next development version: ' + version
160 |
161 | MavenDescriptor descriptor = artifactory.mavenDescriptor()
162 | descriptor.setVersion(version)
163 | descriptor.setFailOnSnapshot(false)
164 | descriptor.transform()
165 |
166 | // set scm/tag to HEAD
167 | computeScmTag('HEAD')
168 |
169 | script.sh "git commit -am 'prepare for next development iteration'"
170 |
171 | // update buildinfo, icon and released version
172 |
173 | }
174 |
175 | String computeReleaseVersion() {
176 | logger.info 'compute release version'
177 |
178 | script.pom = script.readMavenPom file: 'pom.xml'
179 | String version = script.pom.version
180 | try {
181 | if (version.endsWith('-SNAPSHOT')) {
182 | version = version.substring(0, version.length() - "SNAPSHOT".length() - 1)
183 | } else {
184 | script.error 'failed to compute release version'
185 | }
186 | } catch (e) {
187 | logger.error e.message
188 | }
189 |
190 | return version
191 | }
192 |
193 | String computeNextVersion() {
194 | String version = script.pom.version
195 | try {
196 | // DefaultVersionInfo dvi = new DefaultVersionInfo(version)
197 | // version = dvi.getNextVersion().getSnapshotVersionString()
198 |
199 |
200 | logger.info 'next development version: ' version
201 | } catch (e) {
202 | logger.info e.message
203 | }
204 |
205 | return version
206 | }
207 |
208 | void computeScmTag(String tag) {
209 | // set scm/tag to '[name]-[version]'
210 | script.pom.scm.tag = tag
211 | script.writeMavenPom model: script.pom
212 | }
213 |
214 | void buildNotifier() {
215 |
216 | def subject = script.env.JOB_NAME + ' - Build #' + script.currentBuild.number + ' - ' + script.currentBuild.currentResult
217 | script.emailext(
218 | to: 'user@domain.com',
219 | subject: subject,
220 | body: script.env.BUILD_URL
221 | // attachLog: true,
222 | //recipientProviders: [[$class: 'DevelopersRecipientProvider']]
223 | )
224 | }
225 | }
226 |
--------------------------------------------------------------------------------
/src/com/tikalk/ci/maven/ArtifactoryPipelineScript.groovy:
--------------------------------------------------------------------------------
1 | package com.tikalk.ci.maven
2 |
3 | import com.tikalk.utils.Library
4 |
5 | @Library('tikal-advanced-pipeline') _
6 |
7 | /**
8 | * Created by ccohen on 7/6/17.
9 | */
10 | node() {
11 | var1 = 'chen1'
12 | def pipeline = new ArtifactoryPipeline(this)
13 |
14 | pipeline.artifactoryName = 'artifactory'
15 | pipeline.mavenName = 'mvn350'
16 |
17 | pipeline.snapshotRepo = 'libs-snapshot-local'
18 | pipeline.releaseRepo = 'libs-release-local'
19 | pipeline.vSnapshotRepo = 'libs-snapshot'
20 | pipeline.vReleaseRepo = 'libs-release'
21 |
22 | pipeline.gitRepoUrl = 'https://github.com/tikalk/tikal-advanced-pipeline.git'
23 | pipeline.gitCredentialsId = '24a699e5-61d4-4d5c-a7ca-38d3f1e50866'
24 |
25 | pipeline.release = this.params.release
26 | pipeline.releaseVersion = this.params.releaseVersion
27 | pipeline.developmentVersion = this.params.developmentVersion
28 |
29 | pipeline.run()
30 | }
31 |
32 | return this
--------------------------------------------------------------------------------
/src/com/tikalk/notifyBuild.groovy:
--------------------------------------------------------------------------------
1 | #!/usr/bin/groovy
2 |
3 | def call(String buildStatus = 'STARTED', String mailContentFile) {
4 | // build status of null means successful
5 | buildStatus = buildStatus ?: 'SUCCESS'
6 |
7 | // Default values
8 | //def TEST = '\${CHANGES, showPaths=true, format="%a: %r %p \n--\"%m\"", pathFormat="\n\t- %p"}'
9 | def colorName = 'RED'
10 | def colorCode = '#FF0000'
11 | def mailSubject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
12 | def mailContent = readFile mailContentFile
13 | // 'popcorn/pipelines/CI-master/summary.html'
14 |
15 | // Override default values based on build status
16 | if (buildStatus == 'STARTED') {
17 | color = 'YELLOW'
18 | colorCode = '#FFFF00'
19 | } else if (buildStatus == 'SUCCESS') {
20 | color = 'GREEN'
21 | colorCode = '#00FF00'
22 | } else {
23 | color = 'RED'
24 | colorCode = '#FF0000'
25 | }
26 |
27 | wrap([$class: 'BuildUser']) {
28 | echo "Send SUMMARY HTML Mail ..."
29 | emailext(to: "${env.DEFAULT_RECIPIENTS}", replyTo: "dorons@tikalk.com",
30 | mimeType: 'text/html', subject: mailSubject, body: mailContent,
31 | recipientProviders: [[$class: 'DevelopersRecipientProvider'],[$class: 'CulpritsRecipientProvider']]);
32 | }
33 | //emailext attachmentsPattern: '**/test.html', body: readFile 'test.html', subject: summary, to: "${env.DEFAULT_RECIPIENTS}", mimeType: 'text/html', recipientProviders: [[$class: 'DevelopersRecipientProvider'],[$class: 'CulpritsRecipientProvider']]
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/tikalk/utils/Library.groovy:
--------------------------------------------------------------------------------
1 | package com.tikalk.utils;
2 |
3 | @interface Library {
4 | String value()
5 | }
--------------------------------------------------------------------------------
/src/com/tikalk/utils/Logger.groovy:
--------------------------------------------------------------------------------
1 | package com.tikalk.utils;
2 |
3 | class Logger implements Serializable {
4 | def script
5 | boolean debugLogging = false
6 |
7 | Logger(script) {
8 | this.script = script
9 | debugLogging = script.params.debugLogging ?: false
10 | }
11 |
12 | void info(String message) {
13 | script.echo message
14 | }
15 |
16 | void debug(String message) {
17 | if (debugLogging) {
18 | script.echo message
19 | }
20 | }
21 |
22 |
23 | }
--------------------------------------------------------------------------------
/src/settings_mail.groovy:
--------------------------------------------------------------------------------
1 | class settings implements Serializable {
2 | private String colorName
3 | private String colorCode
4 | private String mailSubject
5 | private String mailContent
6 | private String buildStatus
7 |
8 | def setcolorName(value) {
9 | colorName = value
10 | }
11 | def getcolorName() {
12 | colorName
13 | }
14 | def setcolorCode(value) {
15 | colorCode = value
16 | }
17 | def getcolorCode() {
18 | colorCode
19 | }
20 |
21 | def setmailSubject(value) {
22 | mailSubject = value
23 | }
24 | def getmailSubject() {
25 | mailSubject
26 | }
27 |
28 | def setmailContent(value) {
29 | mailContent = value
30 | }
31 | def getmailContent() {
32 | mailContent
33 | }
34 |
35 | def setbuildStatus(value) {
36 | buildStatus = currentBuild.result
37 | }
38 | def getbuildStatus() {
39 | buildStatus
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/test/pipelines/BASIC-CI-FLOW-DEMO/declarative/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline
2 | {
3 | agent any
4 | stages
5 | {
6 | stage('Code commit')
7 | {
8 | steps
9 | {
10 | echo "Code commit"
11 | }
12 | }
13 | stage('Code build')
14 | {
15 | steps
16 | {
17 | echo "Code build"
18 | }
19 | }
20 | stage('Unit tests')
21 | {
22 | steps
23 | {
24 | echo "Unit tests"
25 | }
26 | }
27 | stage('Deploy')
28 | {
29 | steps
30 | {
31 | echo "Deploy"
32 | }
33 | }
34 | stage('Integration tests')
35 | {
36 | steps
37 | {
38 | echo "Integration tests"
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/test/pipelines/BASIC-CI-FLOW-DEMO/scripted/Jenkinsfile:
--------------------------------------------------------------------------------
1 | node
2 | {
3 | stage('Code commit')
4 | {
5 | echo "Code commit"
6 | }
7 | stage('Code build')
8 | {
9 | echo "Code build"
10 | }
11 | stage('Unit tests')
12 | {
13 | echo "Unit tests"
14 | }
15 | stage('Deploy')
16 | {
17 | echo "Deploy"
18 | }
19 | stage('Integration tests')
20 | {
21 | echo "Integration tests"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/test/pipelines/The_Force_Awakens/declarative/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline
2 | {
3 | parameters
4 | {
5 | string(name: 'SEQUENCE', defaultValue: '', description: 'Star Wars movie sequence number')
6 | }
7 |
8 | options
9 | {
10 | buildDiscarder(logRotator(numToKeepStr: '50'))
11 | ansiColor('xterm')
12 | timestamps()
13 | }
14 |
15 | agent any
16 | stages
17 | {
18 | stage('Setup')
19 | {
20 | steps
21 | {
22 | script
23 | {
24 | currentBuild.displayName = "#${BUILD_ID} | ${SEQUENCE}"
25 | }
26 | checkout([$class: 'GitSCM', branches: [[name: 'master']],
27 | userRemoteConfigs: [[url: 'https://github.com/tikalk/maven-hello-world']]
28 | ])
29 | }
30 | }
31 | stage('Code build')
32 | {
33 | steps
34 | {
35 | withMaven(jdk: 'jdk8u131', maven: 'mvn350')
36 | {
37 | sh "mvn clean install -DskipTests -f my-app/pom.xml"
38 | }
39 | }
40 | }
41 | stage('Unit tests')
42 | {
43 | steps
44 | {
45 | withMaven(jdk: 'jdk8u131', maven: 'mvn350')
46 | {
47 | sh "mvn test -f my-app/pom.xml"
48 | }
49 | }
50 | }
51 | stage('Integration tests')
52 | {
53 | steps
54 | {
55 | sh "java -jar my-app/target/my-app-1.0-SNAPSHOT.jar ${SEQUENCE}"
56 | }
57 | }
58 | }
59 | post
60 | {
61 | always
62 | {
63 | junit 'my-app/target//surefire-reports/*.xml'
64 | archiveArtifacts '**/target/**/my-app-*.jar'
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/test/pipelines/The_Force_Awakens/scripted/Jenkinsfile:
--------------------------------------------------------------------------------
1 | properties([parameters([string(defaultValue: '', description: 'Star Wars movie sequence number', name: 'SEQUENCE')]), pipelineTriggers([])])
2 |
3 | node
4 | {
5 | stage('Setup')
6 | {
7 | currentBuild.displayName = "#${BUILD_ID} | ${SEQUENCE}"
8 | checkout([$class: 'GitSCM', branches: [[name: 'master']],
9 | userRemoteConfigs: [[url: 'https://github.com/tikalk/maven-hello-world']]
10 | ])
11 | }
12 | stage('Code build')
13 | {
14 | withMaven(jdk: 'jdk8u131', maven: 'mvn350')
15 | {
16 | sh "mvn clean install -DskipTests -f my-app/pom.xml"
17 | }
18 | }
19 | stage('Unit tests')
20 | {
21 | withMaven(jdk: 'jdk8u131', maven: 'mvn350')
22 | {
23 | sh "mvn test -f my-app/pom.xml"
24 | }
25 | }
26 | stage('Integration tests')
27 | {
28 | sh "java -jar my-app/target/my-app-1.0-SNAPSHOT.jar ${SEQUENCE}"
29 | }
30 | stage('JUnit report')
31 | {
32 | junit 'my-app/target//surefire-reports/*.xml'
33 | }
34 | stage('Archive artifacts')
35 | {
36 | archiveArtifacts '**/target/**/my-app-*.jar'
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/test/pipelines/advanced_slack_notification/Jenkinsfile:
--------------------------------------------------------------------------------
1 | @Library("tikal-advanced-pipeline") _
2 |
3 | pipeline
4 | {
5 | agent any
6 | stages
7 | {
8 | stage('TEST')
9 | {
10 | steps
11 | {
12 | echo "Testing Advanced Slack Notification"
13 | }
14 | }
15 | }
16 | post
17 | {
18 | success
19 | {
20 | TAP_advancedSlackNotification('SUCCESS',"tap-tests")
21 | }
22 |
23 | failure
24 | {
25 | TAP_advancedSlackNotification('FAILURE',"tap-tests")
26 | }
27 |
28 | unstable
29 | {
30 | TAP_advancedSlackNotification('UNSTABLE',"tap-tests")
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test/pipelines/echo_test/Jenkinsfile:
--------------------------------------------------------------------------------
1 | @Library ("tikal-advanced-pipeline") _
2 |
3 | properties([parameters([string(name: 'TEXT', defaultValue: 'Test TEXT')])])
4 |
5 | TAP_echo (env.TEXT)
6 |
--------------------------------------------------------------------------------
/test/pipelines/email_flow/Jenkinsfile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env groovy
2 |
3 | @Library("tikal-advanced-pipeline") _
4 |
5 | pipeline
6 | {
7 | agent any
8 | stages
9 | {
10 | stage('Code Update')
11 | {
12 | steps
13 | {
14 | echo "===================== 0.0 ========================"
15 | }
16 | }
17 | }
18 | post {
19 | success {
20 | echo "===================== 1.0 ========================"
21 | TAP_email('SUCCESS','sample.html')
22 | echo "===================== 2.0 ========================"
23 | }
24 | failure {
25 | TAP_email('FAILURE','sample.html')
26 | }
27 | unstable {
28 | TAP_email('UNSTABLE','sample.html')
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/test/python/generic_python_runner/requirements.txt:
--------------------------------------------------------------------------------
1 | numpy==1.13.1
2 |
--------------------------------------------------------------------------------
/test/python/generic_python_runner/simple.py:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | # Fractional number.
4 | n = 100.7
5 |
6 | # Absolute value.
7 | print(math.floor(n))
8 | print(math.ceil(n))
9 |
--------------------------------------------------------------------------------
/vars/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # ***tikal-Advanced-Pipeline available tasks***
3 |
4 | Powered by **[Tikal Knowledge](http://www.tikalk.com)** and the community.
5 |
6 |
7 | ## TAP_advancedSlackNotification
8 |
9 | ***Send a well-formatted Slack notification***
10 |
11 | #### Task usage
12 |
13 | TAP_advancedSlackNotification(arguments)
14 |
15 | Arguments:
16 |
17 | | Argument name and type | Description | Default Value |
18 | | ------------- | ----------- | ------------- |
19 | | String buildStatus| Build status| N/A|
20 | | String channel| Slack channel| N/A|
21 | | String additionalMessageText| Additional text to the notification message| empty text|
22 |
23 | #### Example
24 | TAP_advancedSlackNotification ("SUCCESS","test-channel","@here")
25 |
26 | ## TAP_echo
27 |
28 | ***Echo text with time-stamp***
29 |
30 | #### Task usage
31 |
32 | TAP_echo(arguments)
33 |
34 | Arguments:
35 |
36 | | Argument name and type | Description | Default Value |
37 | | ------------- | ----------- | ------------- |
38 | | String text| Text to display| N/A|
39 |
40 | #### Example
41 | TAP_echo ("Hello TAP!")
42 |
43 | #### Output
44 | [20170715-05:40:11.393] Hello TAP!
45 |
46 | ## TAP_email
47 |
48 | ***Send email notification using the EmailExt plugin***
49 |
50 | ##### Task usage
51 |
52 | TAP_email(arguments)
53 |
54 | Arguments:
55 |
56 | | Argument name and type | Description | Default Value |
57 | | ------------- | ----------- | ------------- |
58 | | String buildStatus | | |
59 | | mailContentFile | | |
60 |
61 | #### Example
62 | TAP_email('FAILURE','sample.html')
63 |
64 | ## TAP_getBuildUserId
65 |
66 | ***Get job acticator user-id***
67 |
68 | #### Task usage example
69 |
70 | def userId = TAP_getBuildUserId()
71 |
72 | ## TAP_setStatusByLogText
73 |
74 | ***set the build status based on searched text in the build log file***
75 |
76 | #### Task usage
77 |
78 | TAP_setStatusByLogText(Arguments)
79 |
80 | Arguments:
81 |
82 | | Argument name and type | Description | Default Value |
83 | | ------------- | ----------- | ------------- |
84 | | String searchText| Text to search| N/A|
85 |
86 | #### Example
87 | TAP_setStatusByLogText ("ERROR")
88 |
89 | #### Output
90 | Found 'ERROR' in build log
91 |
92 |
--------------------------------------------------------------------------------
/vars/TAP_advancedSlackNotification.groovy:
--------------------------------------------------------------------------------
1 | def call(String buildStatus, String channel, String additionalMessageText = "") {
2 |
3 | buildStatus = buildStatus ?: 'SUCCESS'
4 |
5 | // Default values
6 | def colorName = 'RED'
7 | def colorCode = '#FF0000'
8 | def icon = ':tired_face: '
9 |
10 | // Override default values based on build status
11 | if (buildStatus == 'STARTED')
12 | {
13 | color = 'YELLOW'
14 | colorCode = '#FFFF00'
15 | icon = ''
16 | }
17 | else if (buildStatus == 'SUCCESS')
18 | {
19 | color = 'GREEN'
20 | colorCode = '#00CF00'
21 | icon = ':+1: '
22 | }
23 | else if (buildStatus == 'FAILURE')
24 | {
25 | color = 'RED'
26 | colorCode = '#FF0000'
27 | icon = ':scream: '
28 | }
29 | else if (buildStatus == 'ABORTED')
30 | {
31 | color = 'GRAY'
32 | colorCode = '#AAAAAA'
33 | icon = ''
34 | }
35 | else
36 | {
37 | color = 'PINK'
38 | colorCode = '#FFCCCC'
39 | icon = ''
40 | }
41 |
42 | def summary = "${icon}*BUILD ${buildStatus}*\n\n[Job] *${env.JOB_NAME} #${env.BUILD_NUMBER}*\n[Name] *${currentBuild.displayName}*\n[Console] ${env.BUILD_URL}/consoleFull\n${additionalMessageText}"
43 | slackSend (color: colorCode, message: summary, channel: "#${channel}" )
44 | }
--------------------------------------------------------------------------------
/vars/TAP_echo.groovy:
--------------------------------------------------------------------------------
1 | #!/usr/bin/groovy
2 |
3 | @NonCPS
4 | def call(String text) {
5 |
6 | def out
7 | def config = new HashMap()
8 | def bindings = getBinding()
9 | config.putAll(bindings.getVariables())
10 | out = config['out']
11 |
12 | def now = new Date()
13 | def tstamp = now.format("yyyyMMdd-HH:mm:ss.SSS", TimeZone.getTimeZone('UTC'))
14 |
15 | echo "["+tstamp+"] " + text;
16 | }
17 |
--------------------------------------------------------------------------------
/vars/TAP_email.groovy:
--------------------------------------------------------------------------------
1 | #!/usr/bin/groovy
2 |
3 | @NonCPS
4 | def call(String buildStatus, String mailContentFile) {
5 | // build status of null means successful
6 | buildStatus = buildStatus ?: 'SUCCESS'
7 |
8 | def out
9 | def config = new HashMap()
10 | def bindings = getBinding()
11 | config.putAll(bindings.getVariables())
12 | out = config['out']
13 |
14 |
15 | out.println "================== Printed do Jenkins console 1 ======================"
16 | out.println "================== buildStatus ${buildStatus} ======================"
17 | out.println "================== JOB_NAME ${env.JOB_NAME} ======================"
18 | out.println "================== BUILD_NUMBER ${env.BUILD_NUMBER} ======================"
19 | out.println "================== BUILD_URL ${env.BUILD_URL} ======================"
20 |
21 | def mailSubject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
22 | out.println "================== mailSubject "+ mailSubject + " ======================"
23 |
24 | out.println "================== Printed do Jenkins console 2 ====================="
25 | out.println "================== Printed do Jenkins console 2 ====================="
26 | out.println "================== Printed do Jenkins console 2 ====================="
27 |
28 | out.println "================== mailContentFile " + mailContentFile + " ====================="
29 |
30 | //String
31 | String mailContent = readFile mailContentFile
32 | //String mailContent = new File(env.WORKSPACE/mailContentFile).text
33 |
34 | out.println "================== 1111111111111 ======================"
35 |
36 | // Requires "user build vars plugin"
37 | wrap([$class: 'BuildUser']) {
38 | out.println "================== Send SUMMARY HTML Mail ... ======================"
39 | emailext(to: "doronshai@gmail.com", replyTo: "dorons@tikalk.com",
40 | mimeType: 'text/html', subject: mailSubject, body: mailContent,
41 | recipientProviders: [[$class: 'DevelopersRecipientProvider'],[$class: 'CulpritsRecipientProvider']]);
42 | }
43 | //emailext attachmentsPattern: '**/test.html', body: readFile 'test.html', subject: summary, to: "${env.DEFAULT_RECIPIENTS}", mimeType: 'text/html', recipientProviders: [[$class: 'DevelopersRecipientProvider'],[$class: 'CulpritsRecipientProvider']]
44 | }
45 |
--------------------------------------------------------------------------------
/vars/TAP_getBuildUserId.groovy:
--------------------------------------------------------------------------------
1 | def call() {
2 | def job = Jenkins.getInstance().getItemByFullName(env.JOB_BASE_NAME, Job.class)
3 | def build = job.getBuildByNumber(env.BUILD_ID as int)
4 | def userId = build.getCause(Cause.UserIdCause).getUserId()
5 | return userId
6 | }
--------------------------------------------------------------------------------
/vars/TAP_setStatusByLogText.groovy:
--------------------------------------------------------------------------------
1 | def call(String searchText) {
2 |
3 | String logText = currentBuild.rawBuild.getLog()
4 | if(logText.contains(searchText))
5 | {
6 | println("Found '${searchText}' in build log")
7 | currentBuild.result = 'FAILURE'
8 | }
9 | }
--------------------------------------------------------------------------------