I have just started learning Jenkinsfile, this article gives simple instructions for the use of incorrect steps hope big guy advice.

A,Blue OceanThe installation

Install in the plug-in library

Restart the Jenkins

Ii. Project creation

Three, the firstJenkinsfile

Since Jenkinsfile supports Groovy syntax, here are some utility files written that way

/** ** / return this /** * pull code * @param gitUrl * @param gitBranch * @param credentialsId * @return */ def gitClone(String gitUrl, String gitBranch, String credentialsId='11eb2bd6-050b-4853-9dd6-8118a8d3e370') { checkout([ $class: 'GitSCM', branches: [[name: gitBranch]], doGenerateSubmoduleConfigurations: false, extensions: [[ $class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: '', trackingSubmodules: false ]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: credentialsId, url: GitUrl]]])} /** * Upload the file to the root directory of the corresponding user * @param IP * @param sourceFiles * @param remoteDirectory * @param removePrefix * @param execCommand Def sshPublish(String IP,String sourceFiles,String remoteDirectory,String removePrefix,String ExecCommand){sshPublisher(Publishers: [sshPublisherDesc(configName: '192.168.137.100', Transfers: [ sshTransfer( cleanRemote: false, excludes: '', execCommand: 'ls', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/temp/springboot-ci/', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/*.jar' ) ], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true ) ] ) }Copy the code
pipeline { agent any environment { APP_VERSION = '' APP_DIR = 'APP_WORKSPACE' APP_WORKSPACE = '${WORKSPACE}/${APP_DIR}' COMMIT_MSG = '' APP_CODE = """${sh( returnStdout: true, script: 'echo ${SYSTEM_NAME#*:}' ).trim()}""" APP_QCBD = """${sh( returnStdout: true, script: 'echo ${QCBD#*:}' ).trim()}""" } parameters { choice(name: 'SYSTEM_NAME', choices: [' BRANCH system: SMS ', 'O&M System: COS '], description:' Please select service ') String (name: 'BRANCH', defaultValue: ', description: Choice (name: 'QCBD', choices: [' Normal release :NO', 'Quick release :YES'], Description :' Release type ')} POST {always {PWD ()}} stages {stage('Init') {steps {script {utils = load ". / script/utils. Groovy "utils. GitClone (' http://192.168.137.200/CI/springboot-ci.git ', '* / ${BRANCH})}}} stage (' Build')  { steps { script { echo 'Building.. 'sh "PWD" if(env.app_qCBD == 'YES'){echo" "}else{sh '/usr/local/maven/bin/mvn clean package - dmaven.test. skip=true'}}}} stage('Deploy') {steps { echo 'Deploying.... ' script{ utils = load "./script/utils.groovy" Utils. SshPublish (' 192.168.137.100 ', 'target / *. Jar', '/ temp/springboot - ci/',' target ', 'ls')}}}}}Copy the code