Skip to content

Description of Jenkinsfile

millchen edited this page Jan 29, 2018 · 1 revision

Jenkins Pipeline as code

Domain Specific Language

A pipeline is a Groovy script that tells jenkins what to do when your Pipeline is run.

node

The node method allocates an executor and creates a temporary workspace.

node('[SPECIFIED_LABEL]') {
    …
}
// [SPECIFIED_LABEL]: specified a name or label for the node

若沒有指定label或name,jenkins就任意指派可用的node來執行。

Example

def gradle(command) {  // groovy function: 封裝 ./gradlew 指令
	sh "./gradlew ${command}"
}

node('master') { // 指定到master node執行此 job
	stage('Sync Source Code') { //自定義stage名稱,執行後會在job detail頁面顯示
		// checkout source code
		// repository uri 已在job configuration裡設定了,所以不用指定
		checkout scm
	}

	stage('Gradle Build') {
		gradle 'clean assembleDebug check jacocoTestReport'
	}

	stage('Publishing Reports') {
		// parse reports並發佈在job detail頁面
		// androidLint, checkstyle, findbugs, pmd, dry, jacoco皆是jenkins plugins
		// 若不知道如何寫groovy script,job頁面功能選單有pipeline syntax可協助
		androidLint 	canComputeNew: false, 
				defaultEncoding: '', 
				healthy: '', 
				pattern: '**/lint*.xml', 
				unHealthy: ''
		checkstyle 	canComputeNew: false, 
				defaultEncoding: '', 
				healthy: '', 
				pattern: '**/build/reports/checkstyle/checkstyle*.xml', 
				unHealthy: ''
		findbugs 	canComputeNew: false, 
				defaultEncoding: '', 
				excludePattern: '', 
				healthy: '', 
				includePattern: '', 
				pattern: '**/build/reports/findbugs*.xml', 
				unHealthy: ''
		pmd 	canComputeNew: false, 
			defaultEncoding: '', 
			healthy: '', 
			pattern: '**/build/reports/pmd*.xml', 
			unHealthy: ''
		dry 	canComputeNew: false, 
			defaultEncoding: '', 
			healthy: '', 
			pattern: '**/build/reports/cpd*.xml', 
			unHealthy: ''
		jacoco()
	}

	stage('Archive build output') {
		// archive apk
		archive '**/*.apk'
	}
}

References

Pipeline as Code with Jenkins
Pipeline Official
Pipeline Example
Publishing HTML reports in Pipeline
Jenkins Pipeline Tutorial
Building a continuous delivery pipeline with gradle and jenkins
specified for property 'reports.enabled File Report Destinations' as it is a directory
pipeline plugin tutorial(deprecated)

Clone this wiki locally