Jenkins build trigger、logRotator、buildDiscarder etc

Declarative Pipeline 与Job DSL的同一个功能的语法命令有些差异,不能直接套用,需要查对应的官方文档。

1.Jenkins Declarative Pipeline

语法如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Jenkinsfile (Declarative Pipeline)
pipeline {
agent { label 'sbt' }
options{
buildDiscarder(logRotator(numToKeepStr:'5'))
disableConcurrentBuilds()
}
triggers{
pollSCM('H/2 * * * 1-5')
}
environment {
MYBRANCH = "${env.BRANCH_NAME}"
NEXUS_URL = '117.121.xxx.xx:443'
BASE_IMAGE_TAG = "${NEXUS_URL}/${GROUP_NAME}/${SERVICE_NAME}"
BRANCH_IMAGE_TAG = "${NEXUS_URL}/${GROUP_NAME}/${SERVICE_NAME}-${MYBRANCH}"
}
...
}

1.1 triggers

1.2 buildDiscarder

1.3 disableConcurrentBuilds

  • 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.

1.4 environment

2.Jenkins Job DSL

语法如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pipelineJob("${AndroidFolder}/nightly-build") {
description """
<h3>
Android Build for nightly build
</h3>
"""
//@midnight This will run at some point between 0:00 and 2:59
triggers{
cron '''TZ=Asia/Shanghai
@midnight
'''
}
logRotator {
artifactNumToKeep(30)
numToKeep(30)
}
throttleConcurrentBuilds {
maxTotal(1)
}
environmentVariables {
env('GIT_URL', gitUrl)
env('GIT_BRANCH', gitBranch)
env('GIT_CREDENTIAL_ID', 'xxxx-git-ssh-private')
}

2.1 triggers

2.2 logRotator

  • artifactDaysToKeep: If specified, artifacts from builds older than this number of days will be deleted, but the logs, history, reports, etc for the build will be kept.
  • artifactNumToKeep: If specified, only up to this number of builds have their artifacts retained.
  • daysToKeep: If specified, build records are only kept up to this number of days.
  • numToKeep: If specified, only up to this number of build records are kept.

2.3 throttleConcurrentBuilds
throttleConcurrentBuilds 需要单独给Jenkins安装插件 Throttle Concurrent Builds

2.4 environmentVariables

More Ref:

  1. https://jenkins.io/doc/book/pipeline/syntax/#available-options
  2. https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-logRotator
  3. https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-triggers
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~