我要评分
获取效率
正确性
完整性
易理解

Jenkins Pipeline Sample Code

The sample code is as follows:

stage('source-code-migration') { 
              steps { 
                echo '====== Source code porting ======'
                sh '''
                    if [ ! -d "./report_dir" ]; then mkdir -p ./report_dir; fi
                    /usr/bin/rm -rf ./report_dir/*.html
                '''
                script{
                  def SRC_MIG_STATUS_CODE = sh(returnStatus: true,
                                              script: 'devkit porting src-mig -i /home/TestData/wtdbg2-2.5 -c make -r html -o ./report_dir')
                  switch(SRC_MIG_STATUS_CODE) {
                      case 0:
                          currentBuild.result = 'SUCCESS'
                          echo '[Source Code Porting] --> No scanning suggestions <--'
                          break
                      case 1:
                          currentBuild.result = 'UNSTABLE'
                          echo '[Source Code Porting]--> The scan result contains only suggestion items<--'
                          break
                      case 5:
                          currentBuild.result = 'FAILURE'
                          echo '[Source Code Porting] --> The scan result contains items that must be modified. <--'
                          break
                      case 3:
                          currentBuild.result = 'ABORTED'
                          echo '[Source Code Porting] --> Scan result timeout <--'
                          break
                      case 4:
                          currentBuild.result = 'ABORTED'
                          echo '[Source Code Porting] --> Incorrect scanning command <--'
                          break
                      default:
                          currentBuild.result = 'ABORTED'
                          echo '[Source Code Porting]-->Abnormally terminated {Ctrl + C | Ctrl + Z} <--'
                          break
                  }
                }
                sh 'mv ./report_dir/src-mig*.html ./report_dir/SourceCodeScanningReport.html' 
              } 
              post { 
                always { 
                  publishHTML(target: [allowMissing: false, 
                              alwaysLinkToLastBuild: false, 
                              keepAll              : true, 
                              reportDir            : './report_dir', 
                              reportFiles          : 'SourceCodeScanningReport.html', 
                              reportName           : 'Source Code Scanning Report'] 
                              ) 
                } 
              } 
            }
  • When using the source code porting function, you are advised to port a source code file before the build process, or scan a software package after the build process.
  • /home/TestData/wtdbg2-2.5 indicates the path to the source code folder or package to be scanned. Replace it with the actual path.
  • For details about the source code porting report, see Viewing Analysis Results.