-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact
More file actions
121 lines (108 loc) · 5.62 KB
/
react
File metadata and controls
121 lines (108 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
pipeline {
agent any
parameters {
string(name: 'DSL_GIT_URL', defaultValue: 'https://github.com/optimize-it/CICD.git', description: 'Git repository URL for shared library')
string(name: 'DSL_BRANCH_NAME', defaultValue: 'main', description: 'Shared Library Branch')
credentials(name: 'GIT_DSL_CREDENTIAL', description: 'Jenkins credential for shared library Git repo', defaultValue: 'your_new_credential_id', required: true)
string(name: 'GIT_SOURCE_CODE_URL', defaultValue: 'https://github.com/bharathkoptit/build_js_react_app.git', description: 'Git repository URL for source code')
string(name: 'SOURCE_CODE_BRANCH_NAME', defaultValue: 'master', description: 'Source Code Branch to build')
credentials(name: 'GIT_SOURCE_CODE_CREDENTIAL', description: 'Jenkins credential for source code Git repo', defaultValue: 'your_new_credential_id', required: true)
string(name: 'DOCKER_REPO', defaultValue: 'bharathoptdocker', description: 'Docker repository')
string(name: 'DOCKER_IMAGE_NAME', defaultValue: 'reactjs', description: 'Docker image name')
string(name: 'DOCKER_IMAGE_TAG', defaultValue: 'latest', description: 'Docker image tag')
credentials(name: 'DOCKER_CREDENTIAL', description: 'Jenkins credential for DockerHub', defaultValue: 'bkdockerid', required: true)
string(name: 'SONAR_PROJECT_KEY', defaultValue: 'bharathkoptit_build_js_react_app', description: 'SonarQube project key')
string(name: 'SONAR_ORGANIZATION', defaultValue: 'myorg24', description: 'SonarQube organization key')
string(name: 'SONAR_SOURCES_DIR', defaultValue: '.', description: 'Source code directory for SonarQube analysis')
credentials(name: 'SONAR_TOKEN', description: 'SonarQube authentication token', defaultValue: 'bharathsonar', required: true)
string(name: 'SONAR_SCANNER_HOME', defaultValue: 'mysonar', description: 'SonarQube scanner tool name')
string(name: 'SONAR_ENV_NAME', defaultValue: 'SonarCloud', description: 'SonarQube environment name')
string(name: 'SONAR_HOST_URL', defaultValue: 'https://sonarcloud.io', description: 'SonarQube server URL')
string(name: 'SONAR_LANGUAGE', defaultValue: 'js', description: 'Programming language of the project')
string(name: 'SONAR_EXCLUSIONS', defaultValue: '', description: 'Files to exclude from SonarQube analysis')
}
stages {
stage('Git Checkout DSL Repo') {
steps {
script {
dir('CICD') {
git branch: params.DSL_BRANCH_NAME,
credentialsId: params.GIT_DSL_CREDENTIAL,
url: params.DSL_GIT_URL
}
}
}
}
stage('Load Scripts') {
steps {
script {
// Define baseDir for Jenkins shared libraries
def baseDir = "${env.WORKSPACE}/CICD/Jenkins/shared-libraries"
// Load scripts using dynamically constructed paths
def loadScript = { type, technology, scriptName ->
def scriptPath = "${baseDir}/${type}/${technology}/${scriptName}.groovy"
return load(scriptPath)
}
// Load scripts from 'vars' directory
gitCheckoutScript = loadScript('vars/common/scm-util', 'git', 'GitCheckout')
sonarScript = loadScript('vars/common', 'codeAnalysis', 'PerformSonarAnalysisForReactjs')
dockerBuildScript = loadScript('vars/common', 'dockerUtil', 'DockerUtil')
dockerPublishScript = loadScript('vars/common', 'containerPublish', 'DockerHubPublish')
// Load scripts from 'src' directory
buildWithNpmScript = loadScript('src/org/common', 'build', 'BuildWithNpm')
unitTestWithNpmScript = loadScript('src/org/common', 'unitTest', 'UnitTestWithNpm')
}
}
}
stage('Git Checkout Source Code Repo') {
steps {
script {
gitCheckoutScript.gitCheckout(params.SOURCE_CODE_BRANCH_NAME, params.GIT_SOURCE_CODE_URL, params.GIT_SOURCE_CODE_CREDENTIAL)
}
}
}
stage('Build') {
steps {
script {
// Example usage of loaded build script
buildWithNpmScript.build()
}
}
}
stage('Unit Test') {
steps {
script {
// Example usage of loaded test script
unitTestWithNpmScript.uniTest()
}
}
}
stage('SonarQube Analysis') {
steps {
script {
sonarScript.performSonarCloudAnalysis('myorg30_reactjs', 'myorg30', '.', 'sonarCloudCredentialsId')
}
}
}
stage('Docker Build') {
steps {
script {
dockerBuildScript.dockerBuild(params.DOCKER_IMAGE_NAME, params.DOCKER_IMAGE_TAG)
}
}
}
stage('Docker Publish') {
steps {
script {
dockerPublishScript.publishToContainer(params.DOCKER_IMAGE_NAME, params.DOCKER_REPO, params.DOCKER_IMAGE_TAG, params.DOCKER_CREDENTIAL)
}
}
}
}
post {
always {
// Clean up or post-processing steps, if any
echo 'Pipeline execution completed.'
}
}
}