Jenkins脚本化管道使用全局时间戳选项

时间:2019-11-09 16:40:55

标签: jenkins jenkins-pipeline

在我的脚本化管道中,我想设置全局type responsewriter struct { w http.ResponseWriter buf bytes.Buffer code int } func (rw *responsewriter) Header() http.Header { return rw.w.Header() } func (rw *responsewriter) WriteHeader(statusCode int) { rw.code = statusCode } func (rw *responsewriter) Write(data []byte) (int, error) { return rw.buf.Write(data) } func (rw *responsewriter) Done() (int64, error) { if rw.code > 0 { rw.w.WriteHeader(rw.code) } return io.Copy(rw.w, &rw.buf) } func handler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { rw := &responsewriter{w: w} next.ServeHTTP(rw, r) if r.Method == "POST" && r.URL.String() == "/login" { foo := rw.Header().Get("X-FOO") setCookie(rw, "MYAPPFOO", foo) } if _, err := rw.Done(); err != nil { log.Println(err) } }) } 选项。

下面的脚本管道不起作用。我们如何在脚本管道中添加这两个选项?

声明性管道

timestamps

脚本管道

ansicolor

1 个答案:

答案 0 :(得分:0)

在使用脚本管道的情况下,您要做的就是用timestampsansiColor('xterm')步骤包装脚本,如下面的示例所示:

node {
    timestamps {
        ansiColor("xterm") {

            stage("A") {
                echo 'This is stage A'
                sh 'printf "\\e[31mHello World\\e[0m\\n"'
                sh "sleep 3s"
            }

            stage("B") {
                echo "This is stage B"
            }
        }
    }
}

enter image description here