Browse Source

add Jenkinsfile

liuyuqi-dellpc 2 months ago
parent
commit
a6ed1f7bc9

+ 40 - 0
android-studio/Jenkinsfile

@@ -0,0 +1,40 @@
+pipeline {
+  agent any
+  stages {
+    stage('检出') {
+      steps {
+        checkout([$class: 'GitSCM',
+        branches: [[name: GIT_BUILD_REF]],
+        userRemoteConfigs: [[
+          url: GIT_REPO_URL,
+          credentialsId: CREDENTIALS_ID
+        ]]])
+      }
+    }
+    stage('编译构建') {
+      agent {
+        docker {
+          reuseNode 'true'
+          registryUrl 'https://coding-public-docker.pkg.coding.net'
+          image 'public/docker/android:29'
+        }
+
+      }
+      post {
+        always {
+          sh './gradlew assembleDebug'
+
+        }
+
+      }
+      steps {
+        sh './gradlew clean && rm -rf ./app/build/'
+      }
+    }
+    stage('上传到 Generic') {
+      steps {
+        codingArtifactsGeneric(credentialsId: "${CODING_ARTIFACTS_CREDENTIALS_ID}", withBuildProps: true, files: 'app/build/outputs/apk/**/*.apk', repoName: "${GENERIC_REPO_NAME}", version: "${CI_BUILD_NUMBER}")
+      }
+    }
+  }
+}

+ 112 - 0
java/spring-docker/Jenkinsfile

@@ -0,0 +1,112 @@
+pipeline {
+  agent any
+  environment {
+    CODING_DOCKER_REG_HOST = "${CCI_CURRENT_TEAM}-docker.pkg.${CCI_CURRENT_DOMAIN}"
+    CODING_DOCKER_IMAGE_NAME = "${PROJECT_NAME.toLowerCase()}/${DOCKER_REPO_NAME}/${DOCKER_IMAGE_NAME}"
+  }
+  stages {
+    stage("检出") {
+      steps {
+        checkout(
+          [$class: 'GitSCM',
+          branches: [[name: GIT_BUILD_REF]],
+          userRemoteConfigs: [[
+            url: GIT_REPO_URL,
+              credentialsId: CREDENTIALS_ID
+            ]]]
+        )
+      }
+    }
+        
+    stage('单元测试') {
+      
+      steps {
+        sh "./gradlew test"
+      }
+      post {
+        always {
+          // 收集测试报告
+          junit 'build/test-results/**/*.xml'
+        }
+      }
+    }
+    
+    stage('编译') {
+      
+      steps {
+        sh "./gradlew build"
+      }
+    }
+    
+    stage('构建镜像并推送到 CODING Docker 制品库') {
+      steps {
+        sh "docker build -t ${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} -f ${DOCKERFILE_PATH} ${DOCKER_BUILD_CONTEXT}"
+        useCustomStepPlugin(
+          key: 'coding-public:artifact_docker_push',
+          version: 'latest',
+          params: [
+            image:"${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}",
+            repo:"${DOCKER_REPO_NAME}"
+          ]
+        )
+      }
+    }
+    
+    stage("部署到远端服务") {
+      steps {
+        script {
+          def remoteConfig = [:]
+          remoteConfig.name = "my-remote-server"
+          remoteConfig.host = "${REMOTE_HOST}"
+          remoteConfig.port = "${REMOTE_SSH_PORT}".toInteger()
+          remoteConfig.allowAnyHosts = true
+
+          withCredentials([
+            sshUserPrivateKey(
+              credentialsId: "${REMOTE_CRED}",
+              keyFileVariable: "privateKeyFilePath"
+            ),
+            usernamePassword(
+              credentialsId: "${CODING_ARTIFACTS_CREDENTIALS_ID}",
+              usernameVariable: 'CODING_DOCKER_REG_USERNAME',
+              passwordVariable: 'CODING_DOCKER_REG_PASSWORD'
+            )
+          ]) {
+            // SSH 登陆用户名
+            remoteConfig.user = "${REMOTE_USER_NAME}"
+            // SSH 私钥文件地址
+            remoteConfig.identityFile = privateKeyFilePath
+
+            // 请确保远端环境中有 Docker 环境
+            sshCommand(
+              remote: remoteConfig,
+              command: "docker login -u ${CODING_DOCKER_REG_USERNAME} -p ${CODING_DOCKER_REG_PASSWORD} ${CODING_DOCKER_REG_HOST}",
+              sudo: true,
+            )
+
+            sshCommand(
+              remote: remoteConfig,
+              command: "docker rm -f java-spring-app | true",
+              sudo: true,
+            )
+
+            // DOCKER_IMAGE_VERSION 中涉及到 GIT_LOCAL_BRANCH / GIT_TAG / GIT_COMMIT 的环境变量的使用
+            // 需要在本地完成拼接后,再传入到远端服务器中使用
+            DOCKER_IMAGE_URL = sh(
+              script: "echo ${CODING_DOCKER_REG_HOST}/${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}",
+              returnStdout: true
+            )
+
+            sshCommand(
+              remote: remoteConfig,
+              command: "docker run -d -p 8080:8080 --name java-spring-app ${DOCKER_IMAGE_URL}",
+              sudo: true,
+            )
+
+            echo "部署成功,请到 http://${REMOTE_HOST}:8080 预览效果"
+          }
+        }
+      }
+    }
+  }
+}

+ 0 - 0
react/.github/workflows/main.yml → nodejs/.github/react/.github/workflows/main.yml


+ 0 - 0
react/.github/workflows/react_go.yml → nodejs/.github/react/.github/workflows/react_go.yml


+ 55 - 0
nodejs/.github/react/pipeline.Jenkinsfile

@@ -0,0 +1,55 @@
+pipeline {
+  agent any
+  stages  {
+    stage("检出") {
+      steps {
+        checkout(
+          [$class: 'GitSCM',
+          branches: [[name: GIT_BUILD_REF]],
+          userRemoteConfigs: [[
+            url: GIT_REPO_URL,
+              credentialsId: CREDENTIALS_ID
+            ]]]
+        )
+      }
+    }
+        
+    // 下述演示的过程依赖于模版示例代码内容,您可以根据自己的实际情况调整构建过程
+
+    stage('安装依赖') {
+      steps {
+        sh "npm install"
+      }
+    }
+    
+    stage('单元测试') {
+      // 测试框架需要构建环境中预装 Chromium 无头浏览器,在该阶段采用仓库内 Dockerfile 指定的镜像作为测试环境
+      
+      steps {
+        sh "npm run test:ci"
+        // 使用 CODING 插件收集测试报告
+        junit '*.xml'
+      }
+    }
+    
+    stage('编译') {
+      
+      steps {
+        sh "npm run build"
+      }
+    }
+    
+    stage('上传到 COS Bucket') {
+      steps {
+        // 配置 COS 信息
+        sh "coscmd config -a ${COS_SECRET_ID} -s ${COS_SECRET_KEY} -b ${COS_BUCKET_NAME} -r ${COS_BUCKET_REGION}"
+        // 在此处填写编译构建生成的文件所在路径,这些文件会被上传到 COS Bucket
+        sh "coscmd upload -r ${COS_UPLOAD_FROM_PATH} /"
+        // 若您开启了 COS 静态网站,也可以直接访问 https://${COS_BUCKET_NAME}.cos-website.${COS_BUCKET_REGION}.myqcloud.com
+        // 您可以通过开启 COS 静态网站功能并配置重定向规则实现部署带有路由功能的 SPA,更多内容请参考 https://cloud.tencent.com/document/product/436/32670
+        echo "上传成功,访问 https://${COS_BUCKET_NAME}.cos-website.${COS_BUCKET_REGION}.myqcloud.com 预览效果"
+        echo "您也可以访问原域名 https://${COS_BUCKET_NAME}.cos.${COS_BUCKET_REGION}.myqcloud.com/index.html 预览效果"
+      }
+    }
+  }
+}

+ 0 - 0
vue/.github/workflows/deploy_aliyun_oss.yml → nodejs/.github/vue/.github/workflows/deploy_aliyun_oss.yml


+ 0 - 0
vue/.github/workflows/main.yml → nodejs/.github/vue/.github/workflows/main.yml


+ 0 - 0
vue/.gitpod.yml → nodejs/.github/vue/.gitpod.yml


+ 111 - 0
python/pipeline-build-flask.jenkinsfile

@@ -0,0 +1,111 @@
+pipeline {
+  agent any
+  environment {
+    CODING_DOCKER_REG_HOST = "${CCI_CURRENT_TEAM}-docker.pkg.${CCI_CURRENT_DOMAIN}"
+    CODING_DOCKER_IMAGE_NAME = "${PROJECT_NAME.toLowerCase()}/${DOCKER_REPO_NAME}/${DOCKER_IMAGE_NAME}"
+  }
+  stages {
+    stage("检出") {
+      steps {
+        checkout(
+          [$class: 'GitSCM',
+          branches: [[name: GIT_BUILD_REF]],
+          userRemoteConfigs: [[
+            url: GIT_REPO_URL,
+              credentialsId: CREDENTIALS_ID
+            ]]]
+        )
+      }
+    }
+        
+    stage('安装依赖') {
+      steps {
+        sh "pip3.7 install -r requirements.txt"
+      }
+    }
+    
+    stage('单元测试') {
+      
+      steps {
+        sh "pytest --junitxml=reports/test-result.xml"
+      }
+      post {
+        always {
+          // 收集测试报告
+          junit 'reports/**/*.xml'
+        }
+      }
+    }
+    
+    stage('构建镜像并推送到 CODING Docker 制品库') {
+      steps {
+        sh "docker build -t ${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} -f ${DOCKERFILE_PATH} ${DOCKER_BUILD_CONTEXT}"
+        useCustomStepPlugin(
+          key: 'coding-public:artifact_docker_push',
+          version: 'latest',
+          params: [
+            image:"${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}",
+            repo:"${DOCKER_REPO_NAME}"
+          ]
+        )
+      }
+    }
+    
+    stage("部署到远端服务") {
+      steps {
+        script {
+          def remoteConfig = [:]
+          remoteConfig.name = "my-remote-server"
+          remoteConfig.host = "${REMOTE_HOST}"
+          remoteConfig.port = "${REMOTE_SSH_PORT}".toInteger()
+          remoteConfig.allowAnyHosts = true
+
+          withCredentials([
+            sshUserPrivateKey(
+              credentialsId: "${REMOTE_CRED}",
+              keyFileVariable: "privateKeyFilePath"
+            ),
+            usernamePassword(
+              credentialsId: "${CODING_ARTIFACTS_CREDENTIALS_ID}",
+              usernameVariable: 'CODING_DOCKER_REG_USERNAME',
+              passwordVariable: 'CODING_DOCKER_REG_PASSWORD'
+            )
+          ]) {
+            // SSH 登陆用户名
+            remoteConfig.user = "${REMOTE_USER_NAME}"
+            // SSH 私钥文件地址
+            remoteConfig.identityFile = privateKeyFilePath
+
+            // 请确保远端环境中有 Docker 环境
+            sshCommand(
+              remote: remoteConfig,
+              command: "docker login -u ${CODING_DOCKER_REG_USERNAME} -p ${CODING_DOCKER_REG_PASSWORD} ${CODING_DOCKER_REG_HOST}",
+              sudo: true,
+            )
+
+            sshCommand(
+              remote: remoteConfig,
+              command: "docker rm -f python-flask-app | true",
+              sudo: true,
+            )
+
+            // DOCKER_IMAGE_VERSION 中涉及到 GIT_LOCAL_BRANCH / GIT_TAG / GIT_COMMIT 的环境变量的使用
+            // 需要在本地完成拼接后,再传入到远端服务器中使用
+            DOCKER_IMAGE_URL = sh(
+              script: "echo ${CODING_DOCKER_REG_HOST}/${CODING_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}",
+              returnStdout: true
+            )
+
+            sshCommand(
+              remote: remoteConfig,
+              command: "docker run -d -p 5000:5000 --name python-flask-app ${DOCKER_IMAGE_URL}",
+              sudo: true,
+            )
+
+            echo "部署成功,请到 http://${REMOTE_HOST}:5000 预览效果"
+          }
+        }
+      }
+    }
+  }
+}