jenkins add timestamps

Timestamper plugin: Adds timestamps to the Console Output

Method One: use options

1
2
3
4
5
6
7
//declarative pipeline
pipeline {
agent any
options {
timestamps ()
}
}

Example output:

1
2
3
4
5
6
7
16:21:40 + echo 23
16:21:40 23
[Pipeline] sh
16:21:41 + echo master , test.BuiltInFunction/Devops_Tools/demo-from-git
16:21:41 master , test.BuiltInFunction/Devops_Tools/demo-from-git
[Pipeline] echo
16:21:41 haha

Method Two: use wrap

//declarative pipeline
pipeline {
    agent any   
    stages {
        stage('Stage with timestamp'){
            steps{
                sh "echo ${env.BUILD_NUMBER}"
                wrap([$class: 'TimestamperBuildWrapper']) {
                  echo "Done"
                }
            }
        }
    }    
}

默认是到分钟级别,到秒级别的需要自己定义格式,或者在菜单左侧,选择“Elapsed time”

More Ref:

打赏