jenkins-generator 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.prettierrc +4 -0
  2. package/README.md +365 -0
  3. package/dist/app.controller.d.ts +6 -0
  4. package/dist/app.controller.js +35 -0
  5. package/dist/app.controller.js.map +1 -0
  6. package/dist/app.controller.spec.d.ts +1 -0
  7. package/dist/app.controller.spec.js +21 -0
  8. package/dist/app.controller.spec.js.map +1 -0
  9. package/dist/app.module.d.ts +2 -0
  10. package/dist/app.module.js +35 -0
  11. package/dist/app.module.js.map +1 -0
  12. package/dist/app.service.d.ts +3 -0
  13. package/dist/app.service.js +20 -0
  14. package/dist/app.service.js.map +1 -0
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +32 -0
  17. package/dist/cli.js.map +1 -0
  18. package/dist/index.d.ts +9 -0
  19. package/dist/index.js +26 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/interfaces/config.interface.d.ts +70 -0
  22. package/dist/interfaces/config.interface.js +3 -0
  23. package/dist/interfaces/config.interface.js.map +1 -0
  24. package/dist/main.d.ts +1 -0
  25. package/dist/main.js +3 -0
  26. package/dist/main.js.map +1 -0
  27. package/dist/services/cicd-generator.service.d.ts +14 -0
  28. package/dist/services/cicd-generator.service.js +158 -0
  29. package/dist/services/cicd-generator.service.js.map +1 -0
  30. package/dist/services/cloud-provider.service.d.ts +9 -0
  31. package/dist/services/cloud-provider.service.js +230 -0
  32. package/dist/services/cloud-provider.service.js.map +1 -0
  33. package/dist/services/jenkinsfile.service.d.ts +14 -0
  34. package/dist/services/jenkinsfile.service.js +414 -0
  35. package/dist/services/jenkinsfile.service.js.map +1 -0
  36. package/dist/services/notification.service.d.ts +10 -0
  37. package/dist/services/notification.service.js +235 -0
  38. package/dist/services/notification.service.js.map +1 -0
  39. package/dist/services/prompt.service.d.ts +16 -0
  40. package/dist/services/prompt.service.js +415 -0
  41. package/dist/services/prompt.service.js.map +1 -0
  42. package/dist/services/security.service.d.ts +9 -0
  43. package/dist/services/security.service.js +95 -0
  44. package/dist/services/security.service.js.map +1 -0
  45. package/dist/services/validation.service.d.ts +8 -0
  46. package/dist/services/validation.service.js +140 -0
  47. package/dist/services/validation.service.js.map +1 -0
  48. package/dist/tsconfig.tsbuildinfo +1 -0
  49. package/eslint.config.mjs +34 -0
  50. package/nest-cli.json +8 -0
  51. package/package.json +67 -0
  52. package/tsconfig.build.json +4 -0
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.JenkinsFileService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const cloud_provider_service_1 = require("./cloud-provider.service");
15
+ const notification_service_1 = require("./notification.service");
16
+ const security_service_1 = require("./security.service");
17
+ let JenkinsFileService = class JenkinsFileService {
18
+ cloudProvider;
19
+ notificationService;
20
+ securityService;
21
+ constructor(cloudProvider, notificationService, securityService) {
22
+ this.cloudProvider = cloudProvider;
23
+ this.notificationService = notificationService;
24
+ this.securityService = securityService;
25
+ }
26
+ generateJenkinsfile(config) {
27
+ const { project, cloud, notifications, jenkinsConfig } = config;
28
+ const dockerImageName = `${project.projectName
29
+ .toLowerCase()
30
+ .replace(/\s+/g, '-')}`;
31
+ const dockerImageTag = '${BUILD_NUMBER}';
32
+ const notificationFunctions = this.notificationService.generateNotificationScript(notifications);
33
+ const deploymentScript = this.cloudProvider.generateDeploymentScript(cloud, dockerImageName);
34
+ const credentialsEnv = this.cloudProvider.generateCredentialsEnvironmentVariables(cloud);
35
+ const jenkinsfile = `// Auto-generated Jenkins Pipeline
36
+ // Generated by Auto-CICD Generator
37
+ // Project: ${project.projectName}
38
+ // Cloud Provider: ${cloud.provider}
39
+ // Generated on: ${new Date().toISOString()}
40
+
41
+ pipeline {
42
+ agent {
43
+ label '${jenkinsConfig.agentLabel}'
44
+ }
45
+
46
+ options {
47
+ timeout(time: ${jenkinsConfig.timeout}, unit: 'MINUTES')
48
+ buildDiscarder(logRotator(numToKeepStr: '10'))
49
+ timestamps()
50
+ disableConcurrentBuilds()
51
+ }
52
+
53
+ ${credentialsEnv}
54
+
55
+ stages {
56
+ stage('Checkout') {
57
+ steps {
58
+ script {
59
+ echo "Checking out code from repository..."
60
+ checkout([
61
+ $class: 'GitSCM',
62
+ branches: [[name: '*/${project.branch}']],
63
+ userRemoteConfigs: [[
64
+ url: '${project.repository}',
65
+ credentialsId: 'git-credentials'
66
+ ]]
67
+ ])
68
+ echo "Code checked out successfully"
69
+ }
70
+ }
71
+ }
72
+
73
+ stage('Install Dependencies') {
74
+ steps {
75
+ script {
76
+ echo "Installing dependencies..."
77
+ ${project.language === 'javascript' ? 'sh "npm ci"' : 'sh "npm ci"'}
78
+ echo "Dependencies installed successfully"
79
+ }
80
+ }
81
+ }
82
+
83
+ ${project.runTests && project.testCommand
84
+ ? this.generateTestStage(project.testCommand, jenkinsConfig.retryCount)
85
+ : ''}
86
+
87
+ stage('Build') {
88
+ steps {
89
+ script {
90
+ echo "Building application..."
91
+ ${project.buildCommand
92
+ ? `sh "${project.buildCommand}"`
93
+ : '// No build command specified'}
94
+ echo "Build completed successfully"
95
+ }
96
+ }
97
+ }
98
+
99
+ stage('Docker Build') {
100
+ steps {
101
+ script {
102
+ echo "Building Docker image..."
103
+ def dockerImage = "${dockerImageName}:${dockerImageTag}"
104
+
105
+ ${project.hasDockerfile
106
+ ? `sh "docker build -t \${dockerImage} -f ${project.dockerfilePath} ."`
107
+ : `error("Dockerfile not found. Please ensure Dockerfile exists in the project.")`}
108
+
109
+ env.DOCKER_IMAGE = dockerImage
110
+ echo "Docker image built: \${dockerImage}"
111
+ }
112
+ }
113
+ }
114
+
115
+ stage('Push Docker Image') {
116
+ steps {
117
+ script {
118
+ echo "Pushing Docker image to registry..."
119
+
120
+ withCredentials([
121
+ usernamePassword(
122
+ credentialsId: 'docker-registry-credentials',
123
+ usernameVariable: 'DOCKER_USERNAME',
124
+ passwordVariable: 'DOCKER_PASSWORD'
125
+ )
126
+ ]) {
127
+ sh '''
128
+ echo "\${DOCKER_PASSWORD}" | docker login -u "\${DOCKER_USERNAME}" --password-stdin
129
+ docker tag \${DOCKER_IMAGE} \${DOCKER_USERNAME}/\${DOCKER_IMAGE}
130
+ docker push \${DOCKER_USERNAME}/\${DOCKER_IMAGE}
131
+ docker logout
132
+ '''
133
+ }
134
+
135
+ // Update DOCKER_IMAGE to include registry
136
+ env.DOCKER_IMAGE = "\${DOCKER_USERNAME}/${dockerImageName}:${dockerImageTag}"
137
+ echo "Docker image pushed successfully"
138
+ }
139
+ }
140
+ }
141
+
142
+ stage('Deploy to ${cloud.provider.toUpperCase()}') {
143
+ steps {
144
+ script {
145
+ echo "Deploying to ${cloud.provider.toUpperCase()}..."
146
+
147
+ retry(${jenkinsConfig.retryCount}) {
148
+ sh '''
149
+ ${deploymentScript}
150
+ '''
151
+ }
152
+
153
+ echo "Deployment to ${cloud.provider.toUpperCase()} completed successfully"
154
+ }
155
+ }
156
+ }
157
+
158
+ stage('Health Check') {
159
+ steps {
160
+ script {
161
+ echo "Performing health check..."
162
+ sleep(time: 30, unit: 'SECONDS')
163
+
164
+ def healthCheckPassed = false
165
+ def maxRetries = 5
166
+ def retryCount = 0
167
+
168
+ while (!healthCheckPassed && retryCount < maxRetries) {
169
+ try {
170
+ // This is a placeholder - you'll need to customize based on your deployment
171
+ sh 'echo "Health check endpoint: ${cloud.deploymentConfig.healthCheckPath}"'
172
+ healthCheckPassed = true
173
+ echo "Health check passed"
174
+ } catch (Exception e) {
175
+ retryCount++
176
+ echo "Health check failed. Attempt \${retryCount}/\${maxRetries}"
177
+ sleep(time: 10, unit: 'SECONDS')
178
+ }
179
+ }
180
+
181
+ if (!healthCheckPassed) {
182
+ error("Health check failed after \${maxRetries} attempts")
183
+ }
184
+ }
185
+ }
186
+ }
187
+
188
+ stage('Cleanup') {
189
+ steps {
190
+ script {
191
+ echo "Cleaning up old Docker images..."
192
+ sh """
193
+ docker image prune -f
194
+ docker container prune -f
195
+ """
196
+ echo "Cleanup completed"
197
+ }
198
+ }
199
+ }
200
+ }
201
+
202
+ ${this.notificationService.generatePostStageNotifications()}
203
+ }
204
+
205
+ // Notification Functions
206
+ ${notificationFunctions}
207
+ `;
208
+ return jenkinsfile;
209
+ }
210
+ generateTestStage(testCommand, retryCount) {
211
+ return `
212
+ stage('Run Tests') {
213
+ steps {
214
+ script {
215
+ echo "Running tests..."
216
+ retry(${retryCount}) {
217
+ sh "${testCommand}"
218
+ }
219
+ echo "Tests completed successfully"
220
+ }
221
+ }
222
+ post {
223
+ always {
224
+ // Publish test results if available
225
+ junit(testResults: '**/test-results/*.xml', allowEmptyResults: true)
226
+ }
227
+ }
228
+ }
229
+ `;
230
+ }
231
+ generateCredentialsSetupGuide(config) {
232
+ const { cloud, notifications } = config;
233
+ let guide = `
234
+ ╔════════════════════════════════════════════════════════════════╗
235
+ ║ JENKINS CREDENTIALS SETUP GUIDE ║
236
+ ╚════════════════════════════════════════════════════════════════╝
237
+
238
+ Please configure the following credentials in Jenkins:
239
+ (Manage Jenkins → Manage Credentials → Global Credentials)
240
+
241
+ 1. GIT CREDENTIALS
242
+ ID: git-credentials
243
+ Type: Username with password
244
+ Scope: Global
245
+ Description: Git repository credentials
246
+
247
+ 2. DOCKER REGISTRY CREDENTIALS
248
+ ID: docker-registry-credentials
249
+ Type: Username with password
250
+ Scope: Global
251
+ Description: Docker Hub or private registry credentials
252
+
253
+ `;
254
+ switch (cloud.provider) {
255
+ case 'aws':
256
+ guide += `
257
+ 3. AWS CREDENTIALS
258
+ - ID: aws-access-key-id
259
+ Type: Secret text
260
+ Secret: ${this.securityService.maskSensitiveData(cloud.credentials['accessKeyId'])}
261
+
262
+ - ID: aws-secret-access-key
263
+ Type: Secret text
264
+ Secret: [Your AWS Secret Access Key]
265
+ `;
266
+ break;
267
+ case 'azure':
268
+ guide += `
269
+ 3. AZURE CREDENTIALS
270
+ - ID: azure-subscription-id
271
+ Type: Secret text
272
+ Secret: ${this.securityService.maskSensitiveData(cloud.credentials['subscriptionId'])}
273
+
274
+ - ID: azure-client-id
275
+ Type: Secret text
276
+ Secret: ${this.securityService.maskSensitiveData(cloud.credentials['clientId'])}
277
+
278
+ - ID: azure-client-secret
279
+ Type: Secret text
280
+ Secret: [Your Azure Client Secret]
281
+
282
+ - ID: azure-tenant-id
283
+ Type: Secret text
284
+ Secret: ${this.securityService.maskSensitiveData(cloud.credentials['tenantId'])}
285
+ `;
286
+ break;
287
+ case 'gcp':
288
+ guide += `
289
+ 3. GCP CREDENTIALS
290
+ - ID: gcp-project-id
291
+ Type: Secret text
292
+ Secret: ${cloud.credentials['projectId']}
293
+
294
+ - ID: gcp-key-file
295
+ Type: Secret file
296
+ File: Upload your GCP service account key JSON file
297
+ `;
298
+ break;
299
+ case 'digitalocean':
300
+ guide += `
301
+ 3. DIGITALOCEAN CREDENTIALS
302
+ - ID: do-api-token
303
+ Type: Secret text
304
+ Secret: [Your DigitalOcean API Token]
305
+ `;
306
+ break;
307
+ }
308
+ guide += `
309
+ 4. NOTIFICATION CREDENTIALS (if applicable)
310
+ Email notifications are configured automatically.
311
+ For webhook-based notifications, ensure the URLs are accessible.
312
+
313
+ ╔════════════════════════════════════════════════════════════════╗
314
+ ║ SECURITY REMINDERS ║
315
+ ╚════════════════════════════════════════════════════════════════╝
316
+
317
+ ⚠️ NEVER commit credentials to version control
318
+ ⚠️ Use Jenkins credential storage for all sensitive data
319
+ ⚠️ Rotate credentials regularly
320
+ ⚠️ Use least-privilege access principles
321
+ ⚠️ Enable audit logging in Jenkins
322
+ ⚠️ Regularly review and remove unused credentials
323
+
324
+ `;
325
+ return guide;
326
+ }
327
+ generateReadme(config) {
328
+ const { project, cloud } = config;
329
+ return `# ${project.projectName} - CI/CD Pipeline
330
+
331
+ ## Auto-generated CI/CD Configuration
332
+
333
+ This Jenkins pipeline was automatically generated by Auto-CICD Generator.
334
+
335
+ ### Project Information
336
+ - **Project Name:** ${project.projectName}
337
+ - **Project Type:** ${project.projectType}
338
+ - **Language:** ${project.language}
339
+ - **Repository:** ${project.repository}
340
+ - **Branch:** ${project.branch}
341
+
342
+ ### Cloud Deployment
343
+ - **Provider:** ${cloud.provider.toUpperCase()}
344
+ - **Region:** ${cloud.region}
345
+ - **Instance Type:** ${cloud.instanceType}
346
+
347
+ ### Pipeline Stages
348
+ 1. **Checkout** - Clone repository
349
+ 2. **Install Dependencies** - Install npm packages
350
+ ${project.runTests ? '3. **Run Tests** - Execute test suite\n' : ''}4. **Build** - Build application
351
+ 5. **Docker Build** - Create Docker image
352
+ 6. **Push Docker Image** - Push to Docker registry
353
+ 7. **Deploy** - Deploy to ${cloud.provider.toUpperCase()}
354
+ 8. **Health Check** - Verify deployment
355
+ 9. **Cleanup** - Remove old images
356
+
357
+ ### Setup Instructions
358
+
359
+ 1. **Install Required Jenkins Plugins:**
360
+ - Docker Pipeline
361
+ - Git
362
+ - Email Extension
363
+ - Pipeline
364
+ - Credentials Binding
365
+ - Blue Ocean (optional, for better UI)
366
+
367
+ 2. **Configure Credentials:**
368
+ See CREDENTIALS_SETUP.md for detailed instructions.
369
+
370
+ 3. **Create Jenkins Pipeline Job:**
371
+ - New Item → Pipeline
372
+ - Configure Git repository
373
+ - Point to Jenkinsfile in repository root
374
+ - Save and run
375
+
376
+ 4. **Verify Deployment:**
377
+ - Monitor pipeline execution
378
+ - Check email notifications
379
+ - Verify application is running in ${cloud.provider.toUpperCase()}
380
+
381
+ ### Customization
382
+
383
+ To modify the pipeline:
384
+ 1. Edit the Jenkinsfile in your repository root
385
+ 2. Commit and push changes
386
+ 3. Jenkins will automatically use the updated pipeline
387
+
388
+ ### Troubleshooting
389
+
390
+ - **Build Fails:** Check Jenkins console output
391
+ - **Deployment Fails:** Verify cloud credentials
392
+ - **Docker Issues:** Ensure Docker is installed on Jenkins agent
393
+ - **Notification Issues:** Verify webhook URLs and email configuration
394
+
395
+ ### Support
396
+
397
+ For issues or questions, refer to:
398
+ - Jenkins Documentation: https://www.jenkins.io/doc/
399
+ - ${cloud.provider.toUpperCase()} Documentation
400
+ - Docker Documentation: https://docs.docker.com/
401
+
402
+ ---
403
+ Generated on: ${new Date().toISOString()}
404
+ `;
405
+ }
406
+ };
407
+ exports.JenkinsFileService = JenkinsFileService;
408
+ exports.JenkinsFileService = JenkinsFileService = __decorate([
409
+ (0, common_1.Injectable)(),
410
+ __metadata("design:paramtypes", [cloud_provider_service_1.CloudProviderService,
411
+ notification_service_1.NotificationService,
412
+ security_service_1.SecurityService])
413
+ ], JenkinsFileService);
414
+ //# sourceMappingURL=jenkinsfile.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jenkinsfile.service.js","sourceRoot":"","sources":["../../src/services/jenkinsfile.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAE5C,qEAAgE;AAChE,iEAA6D;AAC7D,yDAAqD;AAG9C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEV;IACA;IACA;IAHnB,YACmB,aAAmC,EACnC,mBAAwC,EACxC,eAAgC;QAFhC,kBAAa,GAAb,aAAa,CAAsB;QACnC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAEJ,mBAAmB,CAAC,MAAkB;QACpC,MAAM,E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'../interfaces/config.interface';
2
+ export declare class NotificationService {
3
+ generateNotificationScript(config: NotificationConfig): string;
4
+ private generateEmailNotification;
5
+ private generateSlackNotification;
6
+ private generateDiscordNotification;
7
+ private generateTeamsNotification;
8
+ private generateTelegramNotification;
9
+ generatePostStageNotifications(): string;
10
+ }
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.NotificationService = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ let NotificationService = class NotificationService {
12
+ generateNotificationScript(config) {
13
+ let script = this.generateEmailNotification(config.email);
14
+ if (config.platforms && config.platforms.length > 0) {
15
+ for (const platform of config.platforms) {
16
+ if (!platform.webhook)
17
+ continue;
18
+ switch (platform.type) {
19
+ case 'slack':
20
+ script += this.generateSlackNotification(platform.webhook);
21
+ break;
22
+ case 'discord':
23
+ script += this.generateDiscordNotification(platform.webhook);
24
+ break;
25
+ case 'teams':
26
+ script += this.generateTeamsNotification(platform.webhook);
27
+ break;
28
+ case 'telegram':
29
+ script += this.generateTelegramNotification(platform.webhook);
30
+ break;
31
+ }
32
+ }
33
+ }
34
+ return script;
35
+ }
36
+ generateEmailNotification(email) {
37
+ return `
38
+ # Email Notification Configuration
39
+ def sendEmailNotification(status, stageName=''){
40
+ def subject = "[\${status}] Jenkins Pipeline - \${env.JOB_NAME} #\${env.BUILD_NUMBER}"
41
+ def body = ""
42
+ <html>
43
+ <body>
44
+ <h2>Jenkins Pipeline Notification</h2>
45
+ <p><strong>Job:</strong> \${env.JOB_NAME}</p>
46
+ <p><strong>Build Number:</strong>\${env.BUILD_NUMBER}</p>
47
+ <p><strong>Status:</strong> <span style="color: \${status == 'SUCCESS' ? 'green': 'red'};">\${status}</span></p>
48
+ \${stageName ? "<p><strong>Stage:</strong> \${stageName}</p>" : ""}
49
+ <p><strong>Duration:</strong> \${currentBuild.durationString}</p>
50
+ <p><strong>Duration:</strong> \${currentBuild.durationString}</p>
51
+ <p><strong>Build URL:</strong> <a href="\${env.BUILD_URL}">\${env.BUILD_URL}</a></p>
52
+ <p><strong>Console Output:</strong> <a href="\${env.BUILD_URL}console">\${env.BUILD_URL}console</a></p>
53
+ <hr>
54
+ <p><strong>Changes:</strong></p>
55
+ <pre>\${currentBuild.changeSets.collect { it.items.collect { "\${it.author} - \${it.msg}" }.join('\\n') }.join('\\n')}</pre>
56
+ </body>
57
+ </html
58
+ """
59
+
60
+ emailect(
61
+ subject: subject,
62
+ body: body,
63
+ to: '${email}'
64
+ mimeType: 'text/html'
65
+ attachLog: status != 'SUCCESS'
66
+ )
67
+ }
68
+ `;
69
+ }
70
+ generateSlackNotification(webhook) {
71
+ return `
72
+ def sendSlackNotification(status, stageName = ''){
73
+ def color = status == 'SUCCESS' ? 'good' : 'danger'
74
+ def message = [
75
+ text: "Jenkins Pipeline \${status}",
76
+ attachments:[[
77
+ color: color,
78
+ title: "Jenkins Pipeline \${status}",
79
+ title_link: "\${env.BUILD_URL}",
80
+ fields: [
81
+ [title: "Status", value: status, short: true],
82
+ [title: "Branch", value: "\${env.BRANCH_NAME}", short: true],
83
+ [title: "Duration", value: "\${currentBuild.durationString}", short: true],
84
+ \${stageName ? "[title: 'Stage', value: '\${stageName}', short: true]," : ""}
85
+ ],
86
+ footer: "Jenkins",
87
+ ts: (System.currentTimeMillis() / 1000).toLong()
88
+ ]]
89
+ ]
90
+ sh """
91
+ curl -X POST '${webhook}' \\
92
+ -H 'Content-Type: application/json' \\
93
+ -d '\${groovy.json.JsonOutput.toJson(message)}'
94
+ """
95
+ }
96
+ `;
97
+ }
98
+ generateDiscordNotification(webhook) {
99
+ return `
100
+ def sendDiscordNotification(status, stageName = '') {
101
+ def color = status == 'SUCCESS' ? 3066993 : 15158332
102
+ def message = [
103
+ embeds: [[
104
+ title: "Jenkins Pipeline \${status}",
105
+ description: "\${env.JOB_NAME} #\${env.BUILD_NUMBER}",
106
+ color: color,
107
+ fields: [
108
+ [name: "Status", value: status, inline: true],
109
+ [name: "Branch", value: "\${env.BRANCH_NAME}", inline: true],
110
+ [name: "Duration", value: "\${currentBuild.durationString}", inline: true],
111
+ \${stageName ? "[name: 'Stage', value: '\${stageName}', inline: true]," : ""}
112
+ ],
113
+ footer: [text: "Jenkins"],
114
+ timestamp: new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'"),
115
+ url: "\${env.BUILD_URL}"
116
+ ]]
117
+ ]
118
+
119
+ sh """
120
+ curl -X POST '${webhook}' \\
121
+ -H 'Content-Type: application/json' \\
122
+ -d '\${groovy.json.JsonOutput.toJson(message)}'
123
+ """
124
+ }
125
+ `;
126
+ }
127
+ generateTeamsNotification(webhook) {
128
+ return `
129
+ def sendTeamsNotification(status, stageName = '') {
130
+ def color = status == 'SUCCESS' ? '00FF00' : 'FF0000'
131
+ def message = [
132
+ "@type": "MessageCard",
133
+ "@context": "http://schema.org/extensions",
134
+ themeColor: color,
135
+ summary: "Jenkins Pipeline \${status}",
136
+ sections: [[
137
+ activityTitle: "Jenkins Pipeline \${status}",
138
+ activitySubtitle: "\${env.JOB_NAME} #\${env.BUILD_NUMBER}",
139
+ facts: [
140
+ [name: "Status", value: status],
141
+ [name: "Branch", value: "\${env.BRANCH_NAME}"],
142
+ [name: "Duration", value: "\${currentBuild.durationString}"],
143
+ \${stageName ? "[name: 'Stage', value: '\${stageName}']," : ""}
144
+ ],
145
+ markdown: true
146
+ ]],
147
+ potentialAction: [[
148
+ "@type": "OpenUri",
149
+ name: "View Build",
150
+ targets: [[
151
+ os: "default",
152
+ uri: "\${env.BUILD_URL}"
153
+ ]]
154
+ ]]
155
+ ]
156
+
157
+ sh """
158
+ curl -X POST '${webhook}' \\
159
+ -H 'Content-Type: application/json' \\
160
+ -d '\${groovy.json.JsonOutput.toJson(message)}'
161
+ """
162
+ }
163
+ `;
164
+ }
165
+ generateTelegramNotification(webhook) {
166
+ const parts = webhook.split('/');
167
+ const botToken = parts[parts.length - 2];
168
+ const chatId = parts[parts.length - 1];
169
+ return `
170
+ def sendTelegramNotification(status, stageName = '') {
171
+ def emoji = status == 'SUCCESS' ? '✅' : '❌'
172
+ def message = """
173
+ \${emoji} *Jenkins Pipeline \${status}*
174
+
175
+ *Job:* \${env.JOB_NAME}
176
+ *Build:* #\${env.BUILD_NUMBER}
177
+ *Status:* \${status}
178
+ *Branch:* \${env.BRANCH_NAME}
179
+ \${stageName ? "*Stage:* \${stageName}" : ""}
180
+ *Duration:* \${currentBuild.durationString}
181
+
182
+ [View Build](\${env.BUILD_URL})
183
+ """
184
+
185
+ sh """
186
+ curl -X POST 'https://api.telegram.org/bot${botToken}/sendMessage' \\
187
+ -H 'Content-Type: application/json' \\
188
+ -d '{
189
+ "chat_id": "${chatId}",
190
+ "text": "\${message.replaceAll('"', '\\\\"')}",
191
+ "parse_mode": "Markdown",
192
+ "disable_web_page_preview": true
193
+ }'
194
+ """
195
+ }
196
+ `;
197
+ }
198
+ generatePostStageNotifications() {
199
+ return `
200
+ post {
201
+ success {
202
+ script {
203
+ sendEmailNotification('SUCCESS')
204
+ try {sendSlackNotification('SUCCESS')} catch(e){}
205
+ try {sendDiscordNotification('SUCCESS')} catch(e){}
206
+ try {sendTeamsNotification('SUCCESS')} catch(e){}
207
+ try {sendTelegramNotification('SUCCESS')} catch(e){}
208
+ }
209
+ }
210
+ failure {
211
+ script {
212
+ sendEmailNotification('FAILURE')
213
+ try {sendSlackNotification('FAILURE')} catch(e){}
214
+ try {sendDiscordNotification('FAILURE')} catch(e){}
215
+ try {sendTeamsNotification('FAILURE')} catch(e){}
216
+ try {sendTelegramNotification('FAILURE')} catch(e){}
217
+ }
218
+ }
219
+ unstable {
220
+ script {
221
+ sendEmailNotification('UNSTABLE')
222
+ try {sendSlackNotification('UNSTABLE')} catch(e){}
223
+ try {sendDiscordNotification('UNSTABLE')} catch(e){}
224
+ try {sendTeamsNotification('UNSTABLE')} catch(e){}
225
+ try {sendTelegramNotification('UNSTABLE')} catch(e){}
226
+ }
227
+ }
228
+ }`;
229
+ }
230
+ };
231
+ exports.NotificationService = NotificationService;
232
+ exports.NotificationService = NotificationService = __decorate([
233
+ (0, common_1.Injectable)()
234
+ ], NotificationService);
235
+ //# sourceMappingURL=notification.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification.service.js","sourceRoot":"","sources":["../../src/services/notification.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAIrC,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,0BAA0B,CAAC,MAA0B;QACnD,IAAI,MAAM,GAAG,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE1D,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpD,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;gBACxC,IAAI,CAAC,QAAQ,CAAC,OAAO;oBAAE,SAAS;gBAEhC,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACtB,KAAK,OAAO;wBACV,MAAM,IAAI,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;wBAC3D,MAAM;oBACR,KAAK,SAAS;wBACZ,MAAM,IAAI,IAAI,CAAC,2BAA2B,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;wBAC7D,MAAM;oBACR,KAAK,OAAO;wBACV,MAAM,IAAI,IAAI,CAAC,yBAAyB,CAAC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interfaces/config.interface';
2
+ import { ValidationService } from './validation.service';
3
+ export declare class PromptService {
4
+ private readonly validationService;
5
+ constructor(validationService: ValidationService);
6
+ collectAllConfigurations(): Promise<CICDConfig>;
7
+ private collectProjectConfig;
8
+ private collectCloudConfig;
9
+ private collectAWSCredentials;
10
+ private collectAzureCredentials;
11
+ private collectGCPCredentials;
12
+ private collectDOCredentials;
13
+ private collectDeploymentConfig;
14
+ private collectNotificationConfig;
15
+ private collectJenkinsConfig;
16
+ }