From 9ea2cb2ae8903ad57f791f00ec5b0a7aaf0796f6 Mon Sep 17 00:00:00 2001 From: "ethan.shen" <200839608@qq.com> Date: Mon, 10 May 2021 17:03:28 +0800 Subject: [PATCH 1/4] Create Jenkinsfile --- Jenkinsfile | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..443fc01 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,71 @@ +pipeline { + agent { + node { + label 'base' + } + } + environment { + DOCKER_CREDENTIAL_ID = 'dockerhub' + KUBECONFIG_CREDENTIAL_ID = 'kubeconfig' + REGISTRY = 'docker.io' + DOCKERHUB_NAMESPACE = 'shaowenchen' + APP_NAME = 'devops-python-sample' + SONAR_CREDENTIAL_ID = 'sonar-token' + } + parameters { + string(name: 'BRANCH_NAME', defaultValue: 'master', description: '') + } + + stages { + stage('拉取代码') { + steps { + container('base') { + checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/shaowenchen/devops-python-sample.git']]]) + } + /* if in scm, you can use: checkout scm */ + } + } + + stage('代码检查') { + steps { + container('base') { + withCredentials([string(credentialsId : "$SONAR_CREDENTIAL_ID" ,variable : 'SONAR_TOKEN' ,)]) { + withSonarQubeEnv('sonar') { + sh '''pip install pkgs/base/* & pip install pkgs/extra/* + coverage erase + cd ./src/ + coverage run --source='.' manage.py test + coverage xml -i + ''' + sh "sonar-scanner -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + } + + } + + } + + } + } + + // stage('推送镜像') { + // steps { + // container('base') { + // withCredentials([usernamePassword(credentialsId : "$DOCKER_CREDENTIAL_ID" ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) { + // sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin' + // sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER .' + // sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER' + // } + + // } + + // } + // } + + // stage('部署') { + // steps { + // kubernetesDeploy(enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID", configs: 'deploy/**') + // } + // } + + } +} From 05b93419e86c2a3a52e30e7f753ac3bdf404e623 Mon Sep 17 00:00:00 2001 From: "ethan.shen" <200839608@qq.com> Date: Mon, 10 May 2021 17:14:39 +0800 Subject: [PATCH 2/4] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 443fc01..3553871 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,7 +20,7 @@ pipeline { stage('拉取代码') { steps { container('base') { - checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/shaowenchen/devops-python-sample.git']]]) + checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/a-ethan/devops-python-sample.git']]]) } /* if in scm, you can use: checkout scm */ } From aac52fa3e6c5bfd0fd615f5919371c5b365687de Mon Sep 17 00:00:00 2001 From: "ethan.shen" <200839608@qq.com> Date: Mon, 10 May 2021 17:17:34 +0800 Subject: [PATCH 3/4] mv shaowenchen --- Jenkinsfile | 2 +- Jenkinsfile-online => Jenkinsfile-online.bak | 0 makefile | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename Jenkinsfile-online => Jenkinsfile-online.bak (100%) diff --git a/Jenkinsfile b/Jenkinsfile index 3553871..2d32296 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { DOCKER_CREDENTIAL_ID = 'dockerhub' KUBECONFIG_CREDENTIAL_ID = 'kubeconfig' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'shaowenchen' + DOCKERHUB_NAMESPACE = 'a-ethan' APP_NAME = 'devops-python-sample' SONAR_CREDENTIAL_ID = 'sonar-token' } diff --git a/Jenkinsfile-online b/Jenkinsfile-online.bak similarity index 100% rename from Jenkinsfile-online rename to Jenkinsfile-online.bak diff --git a/makefile b/makefile index 99aeb49..1e7a3a5 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ run: - docker build -f Dockerfile-online -t shaowenchen/demo . - docker run -d -p 8011:8000 --name python-demo shaowenchen/demo + docker build -f Dockerfile-online -t a-ethan/demo . + docker run -d -p 8011:8000 --name python-demo a-ethan/demo test: curl localhost:8011 stop: From 94233da267f08bb6796d4a291678d1b7d0a3d42a Mon Sep 17 00:00:00 2001 From: "ethan.shen" <200839608@qq.com> Date: Mon, 10 May 2021 17:20:09 +0800 Subject: [PATCH 4/4] Update Jenkinsfile --- Jenkinsfile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2d32296..1e72730 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,26 +26,26 @@ pipeline { } } - stage('代码检查') { - steps { - container('base') { - withCredentials([string(credentialsId : "$SONAR_CREDENTIAL_ID" ,variable : 'SONAR_TOKEN' ,)]) { - withSonarQubeEnv('sonar') { - sh '''pip install pkgs/base/* & pip install pkgs/extra/* - coverage erase - cd ./src/ - coverage run --source='.' manage.py test - coverage xml -i - ''' - sh "sonar-scanner -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" - } + // stage('代码检查') { + // steps { + // container('base') { + // withCredentials([string(credentialsId : "$SONAR_CREDENTIAL_ID" ,variable : 'SONAR_TOKEN' ,)]) { + // withSonarQubeEnv('sonar') { + // sh '''pip install pkgs/base/* & pip install pkgs/extra/* + // coverage erase + // cd ./src/ + // coverage run --source='.' manage.py test + // coverage xml -i + // ''' + // sh "sonar-scanner -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + // } - } + // } - } + // } - } - } + // } + // } // stage('推送镜像') { // steps {