JF_CLI jenkinsfile

This commit is contained in:
Krishna Manchikalapudi 2024-07-01 18:23:14 -07:00
parent 2dbeefbf4f
commit c669c1ba08
7 changed files with 268 additions and 1446 deletions

View file

@ -0,0 +1,10 @@
version: 1
type: maven
resolver:
serverId: psazuse
snapshotRepo: krishnam-mvn-virtual
releaseRepo: krishnam-mvn-virtual
deployer:
serverId: psazuse
snapshotRepo: krishnam-mvn-dev-local
releaseRepo: krishnam-mvn-local

158
Jenkinsfile.jfrog-cli Normal file
View file

@ -0,0 +1,158 @@
node {
JF_RT_URL="https://psazuse.jfrog.io"
JFROG_NAME="psazuse"
# https://github.com/krishnamanchikalapudi/spring-petclinic
projectName="spring-petclinic"
JF_CLI_LOG_LEVEL='DEBUG'
stage('init') {
stage('jf.ver') {
sh """ #!/bin/bash
jf -v
"""
} // stage: jf.ver
stage('rt.config') {
// jenkins secrets: https://www.jenkins.io/doc/book/using/using-credentials/
// JFrog CLI config
withCredentials([usernamePassword(credentialsId: 'JFROG_ARTIFACTORY_CLI', passwordVariable: 'JFROG_RT_PWD', usernameVariable: 'JFROG_RT_USER')]) {
sh """ #!/bin/bash
jf config add ${JFROG_NAME} --artifactory-url=${JF_RT_URL}/artifactory --xray-url=${JF_RT_URL}/xray --user=${JFROG_RT_USER} --password=${JFROG_RT_PWD} --interactive=false --overwrite
"""
} // withCredentials: JFROG_ARTIFACTORY
} // stage: rt.config
stage('rt.ping') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf rt ping
"""
} // stage: rt.ping
stage('config.show') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
echo "\n"
jf config show
"""
} // stage: config.show
} // stage: init
stage('Code') {
stage('clone') {
git branch: 'main', url: 'https://github.com/krishnamanchikalapudi/spring-petclinic.git'
} // stage: clone
stage('mvnc') {
repoPath="krishnam-mvn"
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf mvnc --server-id-resolve ${JFROG_NAME} --server-id-deploy ${JFROG_NAME} --repo-resolve-releases ${repoPath}-virtual --repo-resolve-snapshots ${repoPath}-virtual --repo-deploy-releases ${repoPath}-local --repo-deploy-snapshots ${repoPath}-dev-local
"""
} // stage: mvnc
stage('audit') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf audit --mvn --extended-table=true --format=simple-json
"""
}
stage('compile') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf rt mvn clean install -DskipTests=true --scan=true --build-name=${projectName} --build-number=${env.BUILD_ID} --detailed-summary=true
"""
} // stage: compile
stage('scan') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf scan . --extended-table=true --format=simple-json
"""
}
} // stage: code
stage('Tests') {
parallel unitTest: {
stage ("unitTest") {
timeout(time: 10, unit: 'MINUTES') {
sh """ #!/bin/bash
mvn test surefire-report:report
echo 'surefire report generated in ${env.JENKINS_URL}job/${env.JOB_NAME}/${env.BUILD_ID}/execution/node/3/ws/target/site/surefire-report.html'
"""
} // timeout
} // stage: unittest
}, checkstyle: {
stage ("checkStyle") {
timeout(time: 2, unit: 'MINUTES') {
sh """ #!/bin/bash
mvn validate
"""
} // timeout
} // stage: validate
}, codeCoverage: {
stage ("codeCoverage") {
timeout(time: 2, unit: 'MINUTES') {
sh """ #!/bin/bash
mvn jacoco:report
echo 'Jacoco report generated in ${env.JENKINS_URL}job/${env.JOB_NAME}/${env.BUILD_ID}/execution/node/3/ws/target/site/jacoco/index.html'
"""
} // timeout
} // stage: Jacoo
} // parallel
} // stage: tests
stage('BuildInfo') {
stage('vcs info') {
timeout(time: 2, unit: 'MINUTES') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf rt bag ${projectName} ${env.BUILD_ID}
"""
} // timeout
} // stage: git info
stage('env info') {
timeout(time: 2, unit: 'MINUTES') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf rt bce ${projectName} ${env.BUILD_ID}
"""
} // timeout
} // stage: env info
stage ('publish') {
timeout(time: 2, unit: 'MINUTES') {
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf rt bp ${projectName} ${env.BUILD_ID} --detailed-summary=true
"""
} // timeout
} // stage: publish
} // stage: BuildInfo
stage("Queries") {
stage('build') {
// echo $BP_RESP_DATA | jq -r 'buildInfo.env.PACKAGE_CATEGORY'
sh """ #!/bin/bash
export JFROG_CLI_LOG_LEVEL='${JF_CLI_LOG_LEVEL}'
jf rt curl /api/build/${projectName}/${env.BUILD_ID}
"""
} // stage: build
} // stage: queries
stage("RBv2") {
stage("create") {
sh """ #!/bin/bash
"""
} // stage: create
stage("promote:New2Dev") {
sh """ #!/bin/bash
"""
} // stage: promote New 2 Dev
stage ("promote:Dev2QA") {
sh """ #!/bin/bash
"""
} // stage: promote Dev 2 QA
} // stage: RBv2
} // node

File diff suppressed because it is too large Load diff

1
build-spec.json Normal file
View file

@ -0,0 +1 @@
{"builds": [{"name": "spring-petclinic", "number": "cmd.2024-07-01-17-27"}]}

View file

@ -1,46 +0,0 @@
# SET meta-data to differentiate application category, such as application or internal-library
# export PACKAGE_CATEGORIES=(APPLICATION LIBRARY)
# export BUILD_ID="cmd.$(date '+%Y-%m-%d-%H-%M')"
export BUILD_NAME="spring-petclinic" && export BUILD_ID="cmd.$(date '+%Y-%m-%d-%H-%M')" && export JFROG_CLI_LOG_LEVEL="DEBUG" && export PACKAGE_CATEGORY='LIBRARY' & export JF_BEARER_TOKEN='cmVmdGtuOjAxOjE3NDg2MzI1MzU6czl4SDNES1F6dGRPZlMzMTdEMktkRmZhTmdB'
# MVN
#jf rt mvn clean install -DskipTests=true --build-name=spring-petclinic --build-number=${BUILD_ID} --detailed-summary=true --scan=true
jf mvn clean install -DskipTests=true --build-name=${BUILD_NAME} --build-number=${BUILD_ID} --detailed-summary=true --scan=true
# bce:build-collect-env - Collect environment variables. Environment variables can be excluded using the build-publish command.
jf rt bce ${BUILD_NAME} ${BUILD_ID}
# bag:build-add-git - Collect VCS details from git and add them to a build.
jf rt bag ${BUILD_NAME} ${BUILD_ID}
# bp:build-publish - Publish build info
jf rt bp ${BUILD_NAME} ${BUILD_ID} --detailed-summary=true
# Curl to get build info
# jf rt curl -XGET '/artifactory/api/build/${BUILD_NAME}/${BUILD_ID}'
curl --location 'https://psazuse.jfrog.io/artifactory/api/build/spring-petclinic/cmd.2024-06-07-16-23' --header 'Content-Type: application/json' --header 'Authorization: Bearer ${JF_BEARER_TOKEN}' | jq -r '.buildInfo.properties'
BP_RESP_DATA=$(curl --location 'https://psazuse.jfrog.io/artifactory/api/build/spring-petclinic/cmd.2024-06-07-16-23' --header 'Content-Type: application/json' --header 'Authorization: Bearer ${JF_BEARER_TOKEN}' | jq -r '.buildInfo.properties')
echo $BP_RESP_DATA | jq -r 'buildInfo.env.PACKAGE_CATEGORY'
# bs:build-scan - Scan a published build-info with Xray. https://psazuse.jfrog.io/xray/api/v2/ci/build
# jf rt bs spring-petclinic ${BUILD_ID}
jf bs ${BUILD_NAME}${BUILD_ID} --rescan=true --fail=false
# rbc:release-bundle-create - Create a release bundle from builds or from existing release bundles
jf rbc ${BUILD_NAME}${BUILD_ID}
echo "{\"builds\": [{\"name\": \"spring-petclinic\", \"number\": \"cmd.2024.05.10.14.10\"}]}" > build-spec.json && jf rbc --sync=true --signing-key=krishnam --builds=build-spec.json "spring-petclinic-bundle" 05.10.14.10
# bpr:build-promote - This command is used to promote build in Artifactory.
jf rt bpr ${BUILD_NAME}${BUILD_ID} krishnam-mvn-qa-local
# rbp:release-bundle-promote - Promote a release bundle
jf rbp ${BUILD_NAME}${BUILD_ID} QA

94
jf-cli.sh Normal file
View file

@ -0,0 +1,94 @@
# SET meta-data to differentiate application category, such as application or internal-library
# export PACKAGE_CATEGORIES=(WEBAPP, SERVICE, LIBRARY, BASEIMAGE)
# Config - Artifactory info
export JF_RT_URL="https://psazuse.jfrog.io" JFROG_NAME="psazuse" JFROG_RT_USER="krishnam" JF_BEARER_TOKEN="<GET_YOUR_OWN_KEY>"
echo " JFROG_NAME: $JFROG_NAME \n JF_RT_URL: $JF_RT_URL \n JFROG_RT_USER: $JFROG_RT_USER \n JFROG_CLI_LOG_LEVEL: $JFROG_CLI_LOG_LEVEL \n "
# MVN
## Config - project
### CLI
export BUILD_NAME="spring-petclinic" BUILD_ID="cmd.$(date '+%Y-%m-%d-%H-%M')" PACKAGE_CATEGORY="WEBAPP"
### Jenkins
export BUILD_NAME=${env.JOB_NAME} BUILD_ID=${env.BUILD_ID} PACKAGE_CATEGORY="WEBAPP"
# References:
# https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
# https://wiki.jenkins.io/JENKINS/Building+a+software+project
### CMD
export RT_PROJECT_REPO="krishnam-mvn"
echo " BUILD_NAME: $BUILD_NAME \n BUILD_ID: $BUILD_ID \n JFROG_CLI_LOG_LEVEL: $JFROG_CLI_LOG_LEVEL \n RT_PROJECT_REPO: $RT_PROJECT_REPO \n "
jf mvnc --server-id-resolve ${JFROG_NAME} --server-id-deploy ${JFROG_NAME} --repo-resolve-releases ${RT_PROJECT_REPO}-virtual --repo-resolve-snapshots ${RT_PROJECT_REPO}-virtual --repo-deploy-releases ${RT_PROJECT_REPO}-local --repo-deploy-snapshots ${RT_PROJECT_REPO}-dev-local
## Audit
jf audit --mvn --extended-table=true
## Create Build
jf mvn clean install -DskipTests=true --build-name=${BUILD_NAME} --build-number=${BUILD_ID} --detailed-summary=true --scan=true
## scan packages
jf scan . --extended-table=true --format=simple-json
## bce:build-collect-env - Collect environment variables. Environment variables can be excluded using the build-publish command.
jf rt bce ${BUILD_NAME} ${BUILD_ID}
## bag:build-add-git - Collect VCS details from git and add them to a build.
jf rt bag ${BUILD_NAME} ${BUILD_ID}
## bp:build-publish - Publish build info
jf rt bp ${BUILD_NAME} ${BUILD_ID} --detailed-summary=true
## bs: Build Scan
jf bs ${BUILD_NAME} ${BUILD_ID} --rescan=true
## RBv2: release bundle - create
echo " BUILD_NAME: $BUILD_NAME \n BUILD_ID: $BUILD_ID \n RT_PROJECT_REPO: $RT_PROJECT_REPO \n RT_PROJECT_RB_SIGNING_KEY: $RT_PROJECT_RB_SIGNING_KEY \n "
echo "{\"builds\": [{\"name\": \"${BUILD_NAME}\", \"number\": \"${BUILD_ID}\"}]}" > build-spec.json && jf rbc --sync=true --url="${JF_RT_URL}" --access-token="${JF_BEARER_TOKEN}" --signing-key="${RT_PROJECT_RB_SIGNING_KEY}" --builds=build-spec.json ${BUILD_NAME} ${BUILD_ID}
## RBv2: release bundle - DEV promote
jf rbp --sync=true --url="${JF_RT_URL}" --access-token="${JF_BEARER_TOKEN}" --signing-key="${RT_PROJECT_RB_SIGNING_KEY}" ${BUILD_NAME} ${BUILD_ID} DEV
## RBv2: release bundle - QA promote
jf rbp --sync=true --url="${JF_RT_URL}" --access-token="${JF_BEARER_TOKEN}" --signing-key="${RT_PROJECT_RB_SIGNING_KEY}" ${BUILD_NAME} ${BUILD_ID} QA
# Curl to get build info
# jf rt curl -XGET '/artifactory/api/build/${BUILD_NAME}/${BUILD_ID}'
curl --location 'https://psazuse.jfrog.io/artifactory/api/build/spring-petclinic/cmd.2024-06-07-16-23' --header 'Content-Type: application/json' --header 'Authorization: Bearer ${JF_BEARER_TOKEN}' | jq -r '.buildInfo.properties'
BP_RESP_DATA=$(curl --location 'https://psazuse.jfrog.io/artifactory/api/build/spring-petclinic/cmd.2024-06-07-16-23' --header 'Content-Type: application/json' --header 'Authorization: Bearer ${JF_BEARER_TOKEN}' | jq -r '.buildInfo.properties')
echo $BP_RESP_DATA | jq -r 'buildInfo.env.PACKAGE_CATEGORY'
# bs:build-scan - Scan a published build-info with Xray. https://psazuse.jfrog.io/xray/api/v2/ci/build
# jf rt bs spring-petclinic ${BUILD_ID}
jf bs ${BUILD_NAME} ${BUILD_ID} --rescan=true --fail=false
# rbc:release-bundle-create - Create a release bundle from builds or from existing release bundles
jf rbc ${BUILD_NAME} ${BUILD_ID}
echo "{\"builds\": [{\"name\": \"spring-petclinic\", \"number\": \"cmd.2024.05.10.14.10\"}]}" > build-spec.json && jf rbc --sync=true --signing-key=krishnam --builds=build-spec.json "spring-petclinic-bundle" 05.10.14.10
# bpr:build-promote - This command is used to promote build in Artifactory.
jf rt bpr ${BUILD_NAME}${BUILD_ID} krishnam-mvn-qa-local
# rbp:release-bundle-promote - Promote a release bundle
jf rbp ${BUILD_NAME}${BUILD_ID} QA

5
jf-cli.wsd Normal file
View file

@ -0,0 +1,5 @@
' https://plantuml.com/sequence-diagram '
participant GitHub as Git
participant Artifactory [
= User
]