Posts

Showing posts with the label jule

Jenkins Groovy email api example

emailext mimeType: 'text/html',                attachLog: true/false,                attachmentsPattern: '**/target/......./text.txt',                subject: ".........",                body: "text/html body",                to:  "recipient emails"         

Jenkins Groovy to read file example

body = readFile(".........path/text.txt")

Jenkins groovy file to read credentials properties from Jenkins application credentials

stages{ ....... stage(){ steps{ withCredentials([usernamePassword(credentialsId:'id',passwordVariable:'pass',usernameVariable:'urd')]){ script{ use ....... ={$id}  {$pass} ........... } } } } .......... }

Groovy pipeline for automatic build trigger

prpeline{ ....... triggers{ cron('H 1,5 * * *') } ......... } CRON expression A CRON expression is a string comprising five or six fields separated by white space [11]  that represents a set of times, normally as a schedule to execute some routine. Comments begin with a comment mark #, and must be on a line by themselves. Field Required Allowed values Allowed special characters Remarks Minutes Yes 0-59 *   ,   - Hours Yes 0-23 *   ,   - Day of month Yes 1-31 *   ,   -   ?   L   W ?   L   W  only in some implementations Month Yes 1-12 or JAN-DEC *   ,   - Day of week Yes 0-6 or SUN-SAT *   ,   -   ?   L   # ?   L   #  only in some implementations Year No 1970-2099 *   ,   - This field is not supported in standard/default implementations.

Jenkins pipeline YML file configuration example

buildPipeline(){ properties([ ..... ]) pipelineRunner{ yml="........file.yml" } }

Jenkins pipeline groovy file configuration example

startPipeline(){ pipelineFileMapping=["branch name", "pipeline_file.groovy"] }

How to discard or delete old builds in jenkins?

Jenkins provide list of internal plugin to manage build: You can use options or properties in the pipeline to manage build. pipeline { options { buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30')) } ... } Or pipeline(){ properties ([ buildDiscarder(logRotator(numToKeepStr: '30')) ]) Parameters for  logRotator  (from  the source code ): daysToKeepStr : history is only kept up to this days. numToKeepStr : only this number of build logs are kept. artifactDaysToKeepStr : artifacts are only kept up to this days. artifactNumToKeepStr : only this number of builds have their artifacts kept.