From 9cd813f698d0e67f14cf49401155924507a24260 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Wed, 3 Aug 2022 18:19:11 +0300 Subject: [PATCH 1/2] CR-13197 --- README.md | 19 ++----------------- example-shell/Jenkinsfile | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a7b1a38..16c4cec 100644 --- a/README.md +++ b/README.md @@ -5,27 +5,12 @@ Using Pipeline configured with * definition: Pipeline script from scm * SCM: GIT * Repositories: https://github.com/codefresh-io/example-jenkins-use-codefresh-report-image.git -* Script path: - * example-agent/Jenkinsfile +* Script path: * example-shell/Jenkinsfile When the pipeline is run, it pulls the script from repo and run it. The script build and image from the Dockerfile and reports that to codefresh using codefresh-report-image container image. - -## Example 1 - Jenkinsfile -Uses jenkins docker plugin and runt the codefresh-report-image script passing the environment settings -``` -agent { - docker { - registryUrl 'https://quay.io' - registryCredentialsId 'quay-id' - image "quay.io/codefresh/codefresh-report-image:0.0.83" - } - } -``` - - -## Example 2 -JenkinsfileShellExample +## Example 1 -JenkinsfileShellExample Uses shell to run docker with env variables by: docker run --env-file=cf_env diff --git a/example-shell/Jenkinsfile b/example-shell/Jenkinsfile index 7c74ce1..0db0421 100644 --- a/example-shell/Jenkinsfile +++ b/example-shell/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { } stage ('Build & Push ') { environment { - CF_IMAGE=credentials('CF_IMAGE') + CF_IMAGE= credentials('CF_IMAGE') } steps { sh 'echo "Building $CF_IMAGE"' @@ -30,29 +30,32 @@ pipeline { stage('report image') { environment { - CF_IMAGE=credentials('CF_IMAGE') - CF_HOST = credentials('CF_RT_HOST') - CF_API_KEY = credentials('CF_API_KEY') + CF_IMAGE= credentials('CF_IMAGE') + CF_HOST= credentials('CF_RT_HOST') + CF_API_KEY= credentials('CF_API_KEY') CF_CONTAINER_REGISTRY_INTEGRATION= 'docker' CF_JIRA_INTEGRATION= 'jira' CF_JIRA_MESSAGE= ''' A message with embedded issue ( i.e. CR-11027 ) that would be use query jira for the ticket ''' - CF_JIRA_PROJECT_PREFIX = 'CR' - CF_GITHUB_TOKEN = credentials('CF_GITHUB_TOKEN') - CF_WORKFLOW_NAME="${env.JOB_NAME}" - CF_WORKFLOW_URL="${env.BUILD_URL}" + CF_JIRA_PROJECT_PREFIX= 'CR' + CF_GITHUB_TOKEN= credentials('CF_GITHUB_TOKEN') + CF_WORKFLOW_NAME= "${env.JOB_NAME}" + CF_WORKFLOW_URL= "${env.BUILD_URL}" } steps { sh ''' - export CF_CI_TYPE='jenkins' + export CF_CI_TYPE="jenkins" + # add workflow details + export CF_WORKFLOW_NAME="${CF_WORKFLOW_NAME:-$JOB_NAME}" + export CF_WORKFLOW_URL="${CF_WORKFLOW_URL:-$BUILD_URL}" # add git branch export CF_GIT_PROVIDER="${CF_GIT_PROVIDER:-github}" WITHOUT_POSTFIX="${GIT_URL%.*}" - export CF_GIT_REPO="${WITHOUT_POSTFIX#*//*/}" + export CF_GIT_REPO="${CF_GIT_REPO:-${WITHOUT_POSTFIX#*//*/}}" # slice branch name from repo/branch - export CF_GIT_BRANCH="${GIT_BRANCH#*/}" + export CF_GIT_BRANCH="${CF_GIT_BRANCH:-${GIT_BRANCH#*/}}" env | cut -f 1 -d "=" | grep -E "^CF_" > cf_env docker run --env-file=cf_env "quay.io/codefresh/codefresh-report-image:latest" ''' From 02eab41245a8ec65d3ac971bb8a429413fd85902 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Wed, 3 Aug 2022 19:49:08 +0300 Subject: [PATCH 2/2] CR-13197 --- example-shell/Jenkinsfile | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/example-shell/Jenkinsfile b/example-shell/Jenkinsfile index 0db0421..8185cf2 100644 --- a/example-shell/Jenkinsfile +++ b/example-shell/Jenkinsfile @@ -30,19 +30,31 @@ pipeline { stage('report image') { environment { + // Name of runtime to implement the enrichment + CF_RUNTIME_NAME= 'codefresh-hosted' + + // Image path to enrich CF_IMAGE= credentials('CF_IMAGE') - CF_HOST= credentials('CF_RT_HOST') + + // Codefresh API key !! Committing a plain text token is a security risk. We highly recommend using encrypted secrets. !! + // Documentation - https://www.jenkins.io/doc/book/using/using-credentials CF_API_KEY= credentials('CF_API_KEY') + + // Name of Container registry integration CF_CONTAINER_REGISTRY_INTEGRATION= 'docker' + + // Name of Jira integration CF_JIRA_INTEGRATION= 'jira' - CF_JIRA_MESSAGE= ''' - A message with embedded issue ( i.e. CR-11027 ) - that would be use query jira for the ticket - ''' + + // String starting with the issue ID to associate with image + CF_JIRA_MESSAGE= 'CR-11027' + + // Jira project filter CF_JIRA_PROJECT_PREFIX= 'CR' + + // GitHub Access token !! Committing a plain text token is a security risk. We highly recommend using encrypted secrets. !! + // Documentation - https://www.jenkins.io/doc/book/using/using-credentials CF_GITHUB_TOKEN= credentials('CF_GITHUB_TOKEN') - CF_WORKFLOW_NAME= "${env.JOB_NAME}" - CF_WORKFLOW_URL= "${env.BUILD_URL}" } steps { sh '''