Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
test_Shared_library_for_projects
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Khawaja Ibrahim Mohiuddin
test_Shared_library_for_projects
Commits
ed0cd3cb
Commit
ed0cd3cb
authored
Jan 20, 2021
by
Khawaja Ibrahim Mohiuddin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added jenkins jobDSL files
parent
e5395305
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
151 additions
and
0 deletions
+151
-0
commonConfig.yaml
resources/commonConfig.yaml
+22
-0
CreateJobs.groovy
src/com/example/CreateJobs.groovy
+47
-0
ReleaseCheck.groovy
src/com/example/ReleaseCheck.groovy
+71
-0
jobs.groovy
vars/jobs.groovy
+5
-0
main.groovy
vars/main.groovy
+6
-0
No files found.
resources/commonConfig.yaml
0 → 100644
View file @
ed0cd3cb
git
:
branchBaseDeployment
:
release.2020.09
:
env
:
dit1
promoteTo
:
eqa1
enabled
:
false
release.2020.10
:
env
:
dit3
promoteTo
:
eqa3
enabled
:
false
release.2020.11
:
env
:
dit2
promoteTo
:
eqa2
enabled
:
false
release.2020.12
:
env
:
dit1
promoteTo
:
eqa1
enabled
:
false
release.2020.13
:
env
:
dit3
promoteTo
:
eqa3
enabled
:
false
\ No newline at end of file
src/com/example/CreateJobs.groovy
0 → 100644
View file @
ed0cd3cb
package
com.example
class
CreateJobs
{
public
Boolean
createPipelineJob
(
String
jobName
,
String
repoUrl
,
String
credentialsID
,
String
srcBranch
,
String
jenkinsfilePath
){
pipelineJob
(
jobName
)
{
definition
{
cpsScm
{
scm
{
git
{
remote
{
name
(
jobName
)
url
(
repoUrl
)
credentials
(
credentialsID
)
}
branch
(
srcBranch
)
}
scriptPath
(
jenkinsfilePath
)
}
}
}
}
}
public
Boolean
createMultibranchPipelineJob
(){
multibranchPipelineJob
(
String
jobName
,
String
repoUrl
,
String
credentialsID
,
String
srcBranch
,
String
jenkinsfilePath
,
List
srcBranches
)
{
branchSources
{
git
{
remote
{
name
(
jobName
)
url
(
repoUrl
)
credentials
(
credentialsID
)
}
includes
(
srcBranches
)
}
scriptPath
(
jenkinsfilePath
)
}
}
}
public
Boolean
createFolder
(
String
foldername
){
folder
(
foldername
)
{
displayName
(
foldername
)
description
(
foldername
+
" folder"
)
}
}
}
\ No newline at end of file
src/com/example/ReleaseCheck.groovy
0 → 100644
View file @
ed0cd3cb
package
com.example
class
ReleaseCheck
{
void
checkExistence
(
String
branch_name
,
String
yaml_path
)
{
appendIfNotExist
(
branch_name
,
yaml_path
)
}
def
appendIfNotExist
(
String
buildName
,
String
fileName
){
// Opening the File
yamlFile
=
new
File
(
fileName
)
// Yaml Reader
def
ys
=
new
YamlSlurper
()
// Parsing the YAML and checking if Branch name exists
yamlFile
.
withReader
{
reader
->
def
yaml
=
ys
.
parse
(
reader
)
def
git_base_branch_to_deploy
=
yaml
.
git
.
branchBaseDeployment
if
(
git_base_branch_to_deploy
[
"$buildName"
])
{
println
"Branch Name to deploy Already Exists"
}
else
{
println
"The branch name $buildName does not exist, appending in the YAML file"
// Append in the File as It doesn't exist
appendNew
(
buildName
)
}
}
}
// A function to append new banch build name according to the conditions
def
appendNew
(
String
newBuildName
)
{
// Data to be appended, will be defined by conditions
def
config
// YamlBuild to convert Groovy Objects to Yaml
def
yaml
=
new
YamlBuilder
()
// End Result String to be Appended in the File
def
end_result
// Conditions to design the YAML object
if
(
newBuildName
.
substring
(
0
,
7
)
==
"release"
){
config
=
[
"$newBuildName"
:
[
env:
"dit1"
,
promoteTo:
"eqa1"
,
enabled:
true
]]
yaml
(
config
)
end_result
=
yaml
.
toString
()
}
else
if
(
newBuildName
.
substring
(
0
,
7
)
==
"develop"
){
config
=
[
"$newBuildName"
:
[
env:
"dit2"
,
promoteTo:
"eq2"
,
enabled:
true
]]
yaml
(
config
)
end_result
=
yaml
.
toString
()
}
else
if
(
newBuildName
.
substring
(
0
,
7
)
==
"feature"
){
config
=
[
"$newBuildName"
:
[
env:
"dev1"
,
promoteTo:
"dev2"
,
enabled:
true
]]
yaml
(
config
)
end_result
=
yaml
.
toString
()
}
else
{
// Handle any other release, other than: release, develop and feature
config
=
[
"$newBuildName"
:
[
env:
"dev1"
,
promoteTo:
"dev2"
,
enabled:
true
]]
yaml
(
config
)
end_result
=
yaml
.
toString
()
}
// As it generates a new Yaml Document, remove the firstline
end_result
=
end_result
.
replace
(
'---'
,
''
)
// Replace 2 spaces with 6 spaces for the children inside <branch_name>
end_result
=
end_result
.
replace
(
" "
,
" "
)
// Append 4 space characters in the first line
// Some Shadowing
end_result
.
eachMatch
(
"$newBuildName"
)
{
ch
->
end_result
=
end_result
.
replace
(
ch
,
" "
+
ch
)}
// Append the End Result string to the YAML file
yamlFile
.
append
(
end_result
)
}
// Function Usage appendIfNotExists('Branch Name (Can only be: release, develop, feature)', 'FileName to read data from and append data to')
}
vars/jobs.groovy
0 → 100644
View file @
ed0cd3cb
import
com.example.ReleaseCheck
import
com.example.CreateJobs
//ReleaseCheck rc = new ReleaseCheck().checkExistence(release,"../resources/commonConfig.yaml")
CreateJobs
job
=
new
CreateJobs
().
createFolder
(
"hello"
)
\ No newline at end of file
vars/main.groovy
0 → 100644
View file @
ed0cd3cb
import
""
def
call
(
String
filepath
)
{
node
{
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment