diff --git a/Jenkinsfile b/Jenkinsfile index 417d86fc..c0599401 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline{ choice(name: 'action', choices: 'create\ndelete', description: 'Choose create/Destroy') string(name: 'ImageName', description: "name of the docker build", defaultValue: 'javapp') string(name: 'ImageTag', description: "tag of the docker build", defaultValue: 'v1') - string(name: 'DockerHubUser', description: "name of the Application", defaultValue: 'praveensingam1994') + string(name: 'DockerHubUser', description: "name of the Application", defaultValue: 'singhmohit14072002') } stages{ @@ -43,26 +43,26 @@ pipeline{ } } } - // stage('Static code analysis: Sonarqube'){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ + stage('Static code analysis: Sonarqube'){ + when { expression { params.action == 'create' } } + steps{ + script{ - // def SonarQubecredentialsId = 'sonarqube-api' - // statiCodeAnalysis(SonarQubecredentialsId) - // } - // } - // } - // stage('Quality Gate Status Check : Sonarqube'){ - // when { expression { params.action == 'create' } } - // steps{ - // script{ + def SonarQubecredentialsId = 'sonarqube-api' + statiCodeAnalysis(SonarQubecredentialsId) + } + } + } + stage('Quality Gate Status Check : Sonarqube'){ + when { expression { params.action == 'create' } } + steps{ + script{ - // def SonarQubecredentialsId = 'sonarqube-api' - // QualityGateStatus(SonarQubecredentialsId) - // } - // } - // } + def SonarQubecredentialsId = 'sonarqube-api' + QualityGateStatus(SonarQubecredentialsId) + } + } + } stage('Maven Build : maven'){ when { expression { params.action == 'create' } } steps{ @@ -72,6 +72,15 @@ pipeline{ } } } + stage('Push JAR to Jfrog : python'){ + when { expression { params.action == 'create'} } + steps{ + script{ + + jarPush() + } + } + } stage('Docker Image Build'){ when { expression { params.action == 'create' } } steps{ diff --git a/jfrog.py b/jfrog.py new file mode 100644 index 00000000..fa3703ae --- /dev/null +++ b/jfrog.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import requests +import subprocess + +def jfrogUpload(): + url = 'http://54.153.105.80:8082/artifactory/example-repo-local/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar' + file_path = '/home/ubuntu/Java_app_3.0/target/kubernetes-configmap-reload-0.0.1-SNAPSHOT.jar' + username = 'admin' + password = 'Mohit@14072002' + + with open(file_path, 'rb') as file: + response = requests.put(url, auth=(username, password), data=file) + + if response.status_code == 201: + print("\nPUT request was successful!") + else: + print(f"PUT request failed with status code {response.status_code}") + print("Response content:") + print(response.text) + + +def mvnBuild(): + + maven_command = "mvn clean install -DskipTests" + + try: + subprocess.run(maven_command, check=True, text=True, shell=True) + print("\nMaven build completed successfully.") + + except subprocess.CalledProcessError as e: + print(f"Error: Maven build failed with exit code {e.returncode}") + + +def main(): + mvnBuild() + jfrogUpload() + +######################################################### +if __name__ == "__main__": + main()