[Jenkins] Pipeline options in jenkinsfile

Normally, Jenkins pipeline settings can done in UI. However, it cannot be version control if settings changed.

Actually, version control can implement in decorative pipeline in jenkinsfile. In this example, it will setup schedule to execute job and setup clean build history settings.

pipeline {
  agent any 
  triggers { 
    // setup schedule job.
    cron('H */4 * * 1-5')
	}
	options {
        // Setup pipeline options.
	buildDiscarder logRotator(numToKeepStr: '7')
	} 
        // Setup pipeline parametets
	properties([
	    parameters([
	        choice(
	            choices: ['ONE', 'TWO'], 
	            name: 'PARAMETER_01'
	        ),
	        booleanParam(
	            defaultValue: true, 
	            description: '', 
	            name: 'BOOLEAN'
	        ),
	        text(
	            defaultValue: '''
	            this is a multi-line 
	            string parameter example
	            ''', 
	             name: 'MULTI-LINE-STRING'
	        ),
	        string(
	            defaultValue: 'scriptcrunch', 
	            name: 'STRING-PARAMETER', 
	            trim: true
	        )
	    ])
	]) 
	currentBranch = GIT_BRANCH
	currentRepositoryPath = sh(returnStdout: true, script: 'git config remote.origin.url').trim() 
}

 

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.