diff --git a/build/Jenkinsfile b/build/Jenkinsfile index 2e4786658..4beea255c 100644 --- a/build/Jenkinsfile +++ b/build/Jenkinsfile @@ -3,9 +3,9 @@ pipeline { environment { NEXUS_VERSION = "nexus3" NEXUS_PROTOCOL = "http" - NEXUS_URL = "172.19.0.3:8081" - NEXUS_REPOSITORY = "maven-nexus-repo" - NEXUS_CREDENTIAL_ID = "e6072e08-87bc-481e-9e4a-55d506546356" + NEXUS_URL = "172.19.0.3:8281" + NEXUS_REPOSITORY = "maven-snapshots" + NEXUS_CREDENTIAL_ID = "deployment"//deployment user REGISTRY = "http://localhost:8281/repository/docker_snapshots/" REGISTRY_CREDENTIAL = "deployment" } @@ -34,7 +34,7 @@ pipeline { } } } -stage("publish to nexus") { +stage('publish to nexus') { steps { script { // Read POM xml file using 'readMavenPom' step , this step 'readMavenPom' is included in: https://plugins.jenkins.io/pipeline-utility-steps @@ -81,33 +81,18 @@ stage("publish to nexus") { } } -stage ('image build and load') { +stage('image build and load') { steps { - script { - pom = readMavenPom file: "pom.xml"; - env.POM_VERSION = ${pom.version} - docker.build registry + ":$POM_VERSION" + script {} + docker.build registry + ":$BUILD_NUMBER" } script { docker.withRegistry( '', REGISTRY_CREDENTIAL ) { dockerImage.push() } } - script { - sh "docker rmi $REGISTRY:${pom.version}" - } } } - post - { - success - { - script - { - env.ARTIFACT_VERSION = $POM_VERSION - } - } - } } } \ No newline at end of file diff --git a/deployment/Jenkinsfile b/deployment/Jenkinsfile index 8a18d6b88..e057ce06d 100644 --- a/deployment/Jenkinsfile +++ b/deployment/Jenkinsfile @@ -3,9 +3,9 @@ pipeline { environment { NEXUS_VERSION = "nexus3" NEXUS_PROTOCOL = "http" - NEXUS_URL = "172.19.0.3:8081" - NEXUS_REPOSITORY = "maven-nexus-repo" - NEXUS_CREDENTIAL_ID = "e6072e08-87bc-481e-9e4a-55d506546356" + NEXUS_URL = "172.19.0.3:8281" + NEXUS_REPOSITORY = "maven-snapshots" + NEXUS_CREDENTIAL_ID = "deployment"//deployment user REGISTRY = "http://localhost:8281/repository/docker_snapshots/" REGISTRY_CREDENTIAL = "deployment" } diff --git a/precommit/Jenkinsfile b/precommit/Jenkinsfile index 1a6ac12e3..1dd738125 100644 --- a/precommit/Jenkinsfile +++ b/precommit/Jenkinsfile @@ -6,6 +6,9 @@ pipeline { triggers { //polls repo every 2 hours from 10am to 19pm on weekdays for changes pollSCM('H H(10-19)/2 * * 1-5') + git branch: "main", "dev" //??? + credentialsId: 'azima-git-ssh', //??? + url: 'git://github.com/VSAzima/spring-petclinic' //??? } options { //reduces dick I/O, may result in losing data @@ -14,7 +17,7 @@ pipeline { stages { stage('pull') { steps { - git branch: "main", + git branch: "main", "dev" credentialsId: 'azima-git-ssh', url: 'git://github.com/VSAzima/spring-petclinic' } diff --git a/promotion/Jenkinsfile b/promotion/Jenkinsfile new file mode 100644 index 000000000..85247b5e6 --- /dev/null +++ b/promotion/Jenkinsfile @@ -0,0 +1,95 @@ +pipeline { + environment { + NEXUS_VERSION = "nexus3" + NEXUS_PROTOCOL = "http" + NEXUS_URL = "172.19.0.3:8281" + NEXUS_REPOSITORY = "maven-releases" + NEXUS_CREDENTIAL_ID = "deployment"//deployment user + REGISTRY = "http://localhost:8281/repository/docker_releases/" + REGISTRY_CREDENTIAL = "deployment" + } + triggers { + + } + stages { + stage('release') { + steps { + script { + withCredentials([file(credentialsId: 'ngx', variable: 'ROOT_CERT'),file(credentialsId:'m2', variable: 'SETTINGS')]) { + docker.image('maven:3.8.1-jdk-8').inside("-u root --network=jenkins_default") { + sh 'cp $ROOT_CERT /usr/local/share/ca-certificates/ && update-ca-certificates && cp $SETTINGS /root/.m2' + sh 'mvn release:perform' + } + } + } + } + } + stage('version') {//change version number + script { + pom = readMavenPom file: "pom.xml"; + VERSION_NUMBER = VersionNumber(versionNumberString: "${pom.version}") + currentBuild.displayName = "${VERSION_NUMBER}" + sh "ant -Dversion=${VERSION_NUMBER} build" + } + } + stage('publish to nexus') { + steps { + script { + // Read POM xml file using 'readMavenPom' step , this step 'readMavenPom' is included in: https://plugins.jenkins.io/pipeline-utility-steps + pom = readMavenPom file: "pom.xml"; + // Find built artifact under target folder + filesByGlob = findFiles(glob: "target/*.${pom.packaging}"); + // Print some info from the artifact found + echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}" + // Extract the path from the File found + artifactPath = filesByGlob[0].path; + // Assign to a boolean response verifying If the artifact name exists + artifactExists = fileExists artifactPath; + + if(artifactExists) { + echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}"; + + nexusArtifactUploader( + nexusVersion: NEXUS_VERSION, + protocol: NEXUS_PROTOCOL, + nexusUrl: NEXUS_URL, + groupId: pom.groupId, + version: pom.version, + repository: NEXUS_REPOSITORY, + credentialsId: NEXUS_CREDENTIAL_ID, + artifacts: [ + // Artifact generated such as .jar, .ear and .war files. + [artifactId: pom.artifactId, + classifier: '', + file: artifactPath, + type: pom.packaging], + + // Lets upload the pom.xml file for additional information for Transitive dependencies + [artifactId: pom.artifactId, + classifier: '', + file: "pom.xml", + type: "pom"] + ] + ); + + } else { + error "*** File: ${artifactPath}, could not be found"; + } + } + + } + } + stage('image build and load') { + steps { + script {} + docker.build registry + ":$BUILD_NUMBER"//change version number + } + script { + docker.withRegistry( '', REGISTRY_CREDENTIAL ) { + dockerImage.push() + } + } + } + } + +} \ No newline at end of file