diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..c61f2ef7a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,70 @@ +pipeline { + agent { label 'UBUNTU_NODE1' } + triggers { pollSCM('* * * * *') } + stages { + stage('get url') { + steps { + git branch: 'sweety', + url: 'https://github.com/Madhuri-chinta/spring-petclinic.git' + } + } + stage('package') { + steps { + sh './mvnw package' + } + } + stage('sonarqube') { + steps { + withSonarQubeEnv('madhuri') { + sh 'mvn clean package sonar:sonar' + } + } + } + stage('artifactory') { + steps { + rtMavenDeployer ( + id: "jfrog", + serverId: "madhuri", + releaseRepo: "madhuri", + snapshotRepo: "madhuri" + ) + } + } + stage ('Exec Maven') { + steps { + rtMavenRun ( + tool: "MAVEN_GOAL", // Tool name from Jenkins configuration + pom: 'pom.xml', + goals: 'clean install', + deployerId: "jfrog" + ) + } + } + + stage ('Publish build info') { + steps { + rtPublishBuildInfo ( + serverId: "madhuri" + ) + } + } + stage('post build') { + steps { + archiveArtifacts artifacts: '**/target/*.jar', + onlyIfSuccessful: true + junit testResults: '**/surefire-reports/TEST-*.xml' + } + } + stage('deploy') { + agent any + steps { + sh 'ansible -i ./ansible/hosts -m ping all' + sh 'ansible-playbook -i ./ansible/hosts ./ansible/spc.yaml' + } + } + } +} + + + + diff --git a/ansible/hosts b/ansible/hosts new file mode 100644 index 000000000..2ab7e044c --- /dev/null +++ b/ansible/hosts @@ -0,0 +1 @@ +172.31.15.26 \ No newline at end of file diff --git a/ansible/madhuri.service b/ansible/madhuri.service new file mode 100644 index 000000000..e906795d7 --- /dev/null +++ b/ansible/madhuri.service @@ -0,0 +1,11 @@ +[Unit] +Description=my springpetclinic application + +[Service] +User=ubuntu +WorkingDirectory=/home/ubuntu +ExecStart=/usr/lib/jvm/java-17-openjdk-amd64/bin/java -jar /home/ubuntu/spring-petclinic-3.0.0-20230314.161709-3.jar +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/ansible/spc.yaml b/ansible/spc.yaml new file mode 100644 index 000000000..c3785283b --- /dev/null +++ b/ansible/spc.yaml @@ -0,0 +1,28 @@ +--- +- name: install springpetclinic + hosts: all + become: yes + tasks: + - name: install java17 and maven + ansible.builtin.apt: + name: + - openjdk-17-jdk + - maven + state: present + update_cache: yes + - name: get url from s3 bucket + ansible.builtin.get_url: + url: https://akshara1413.s3.ap-south-1.amazonaws.com/spring-petclinic-3.0.0-20230314.161709-3.jar + dest: /home/ubuntu + - name: copy service file + ansible.builtin.copy: + src: ./madhuri.service + dest: /etc/systemd/system/spring.service + - name: deamon-reload service + ansible.builtin.systemd: + state: started + daemon_reload: true + enabled: true + name: spring.service + + diff --git a/azure-pipelines-1.yml b/azure-pipelines-1.yml new file mode 100644 index 000000000..3544565be --- /dev/null +++ b/azure-pipelines-1.yml @@ -0,0 +1,11 @@ +--- +pool: + name: Default +trigger: + - main +steps: + - script: echo $(Build.ArtifactStagingDirectory) + + + + \ No newline at end of file diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml new file mode 100644 index 000000000..5af636caa --- /dev/null +++ b/azure-pipelines.yaml @@ -0,0 +1,27 @@ +--- +pool: + name: default +trigger: + - main +steps: + - task: Maven@3 + inputs: + mavenPOMFile: 'pom.xml' + publishJUnitResults: true + goals: 'package' + testResultsFiles: '**/surefire-reports/TEST-*.xml' + javaHomeOption: 'Path' + jdkDirectory: /usr/lib/jvm/java-17-openjdk-amd64 + mavenVersionOption: 'path' + mavenDirectory: /home/ubuntu/spring-petclinic + - task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: '$(Build.Repository.LocalPath)' + ArtifactName: 'drop' + publishLocation: 'Container' + - task: DownloadPipelineArtifact@2 + inputs: + buildType: 'current' + artifactName: 'drop' + targetPath: '/home/ubuntu/spc' + - script: ansible-playbook -i host spc1.yaml \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..86fd564d9 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,22 @@ +pool: + name: "Azure Pipelines" + vmImage: "ubuntu-22.04" +trigger: + - main +jobs: + - job: "gradle" + displayName: "gradle job" + steps: + - task: Gradle@3 + inputs: + gradleWrapperFile: 'gradlew' + workingDirectory: '$(Build.Repository.LocalPath)' + tasks: 'build' + publishJUnitResults: true + testResultsFiles: '**/TEST-*.xml' + javaHomeOption: 'JDKVersion' + sonarQubeRunAnalysis: false + spotBugsAnalysis: false + + + \ No newline at end of file