github.com/verrazzano/verrazzano@v1.7.0/ci/test-examples/Jenkinsfile (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 pipeline { 5 agent { 6 docker { 7 image "${RUNNER_DOCKER_IMAGE}" 8 args "${RUNNER_DOCKER_ARGS}" 9 registryUrl "${RUNNER_DOCKER_REGISTRY_URL}" 10 registryCredentialsId 'ocir-pull-and-push-account' 11 label '2.0-small' 12 } 13 } 14 15 parameters { 16 string (name: 'BASE_TAG', 17 defaultValue: '1.0.0-1', 18 description: 'Base value used as part of generated image tag', 19 trim: true) 20 } 21 22 environment { 23 DOCKER_NAMESPACE = 'verrazzano' 24 DOCKER_CREDS = credentials('github-packages-credentials-rw') 25 DOCKER_REPO = 'ghcr.io' 26 DOCKER_REPO_URL = "https://${DOCKER_REPO}" 27 NETRC_FILE = credentials('netrc') 28 29 OCI_CLI_TENANCY = credentials('oci-tenancy') 30 OCI_CLI_USER = credentials('oci-user-ocid') 31 OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint') 32 OCI_CLI_KEY_FILE = credentials('oci-api-key') 33 OCI_CLI_REGION = 'us-phoenix-1' 34 35 // image name and tag are created from this variable 36 HELLO_WEBLOGIC = 'weblogic-app' 37 VERSION = get_image_tag() 38 39 // access to GitHub Packages Maven Repository 40 MAVEN_SETTINGS = credentials('oracle-maven-settings') 41 42 BUCKET_NAME = "build-shared-files" 43 JDK11_BUNDLE = "openjdk-11+28_linux-x64_bin.tar.gz" 44 } 45 46 stages { 47 stage('Initialize') { 48 steps { 49 sh """ 50 find $WORKSPACE -mindepth 1 -maxdepth 1 | xargs rm -rf 51 """ 52 sh """ 53 cp -f "${NETRC_FILE}" $HOME/.netrc 54 chmod 600 $HOME/.netrc 55 """ 56 } 57 } 58 59 stage('Default checkout') { 60 steps { 61 script { 62 def scmURL = scm.getUserRemoteConfigs()[0].getUrl() 63 defaultCheckoutTargetDir = scmURL.replaceAll(/^.*\//,'').replaceAll(/\.git$/, '') 64 } 65 checkout([ 66 $class: 'GitSCM', 67 branches: scm.branches, 68 extensions: scm.extensions + [[$class: 'RelativeTargetDirectory', relativeTargetDir: defaultCheckoutTargetDir]], 69 userRemoteConfigs: scm.userRemoteConfigs 70 ]) 71 } 72 } 73 74 stage('Prepare Environment') { 75 steps { 76 getMavenSeedData '/build-shared-files' 77 sh """ 78 mkdir -p $HOME/.m2/repository/com 79 tar xz -C $HOME/.m2/repository/com -f /build-shared-files/oracle-maven.tar.gz 80 sudo yum -y install wget 81 echo "${DOCKER_CREDS_PSW}" | docker login ghcr.io -u ${DOCKER_CREDS_USR} --password-stdin 82 """ 83 } 84 } 85 86 stage('Build Test Application') { 87 stages { 88 stage('Build WebLogic Application') { 89 steps { 90 sh """ 91 cd ${WORKSPACE}/verrazzano/tests/testdata/test-applications/weblogic/hello-weblogic 92 mvn -B -s $MAVEN_SETTINGS clean install 93 cd setup 94 ./build.sh ${DOCKER_REPO}/${DOCKER_NAMESPACE}/${HELLO_WEBLOGIC}:${VERSION} 95 docker push ${DOCKER_REPO}/${DOCKER_NAMESPACE}/${HELLO_WEBLOGIC}:${VERSION} 96 """ 97 } 98 } 99 100 stage('Scan WebLogic Application') { 101 steps { 102 scanContainerImage("${DOCKER_REPO}/${DOCKER_NAMESPACE}/${HELLO_WEBLOGIC}:${VERSION}") 103 } 104 post { 105 always { 106 sh """ 107 mv ${WORKSPACE}/scanning-report-grype.json ${WORKSPACE}/hello_weblogic_scanning-report-grype.json 108 mv ${WORKSPACE}/scanning-report-trivy.json ${WORKSPACE}/hello_weblogic_scanning-report-trivy.json 109 """ 110 archiveArtifacts artifacts: '**/*scanning-report*.json', allowEmptyArchive: true 111 } 112 } 113 } 114 } 115 } 116 } 117 } 118 119 def get_image_tag() { 120 time_stamp = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 121 short_commit_sha = sh(returnStdout: true, script: "git rev-parse --short HEAD").trim() 122 if ( env.BRANCH_NAME == 'master' ) { 123 docker_image_tag = params.BASE_TAG + "-" + time_stamp + "-" + short_commit_sha 124 } else { 125 docker_image_tag = time_stamp + "-" + short_commit_sha 126 } 127 println("image tag: " + docker_image_tag) 128 return docker_image_tag 129 }