【问题标题】:How to save the commands history of a Jenkins build run?如何保存 Jenkins 构建运行的命令历史记录?
【发布时间】:2020-04-28 10:12:15
【问题描述】:

我编写了一个声明式 Jenkins 管道,并希望跟踪 Jenkins 执行的 CLI 突击队。为此,我在其中添加了一个阶段和步骤sh 'history -a'

pipeline {
    options {
        ...
    }
    agent {
        node {
            ...
        }
    }
    stages {
        stage('Build') {
            steps {
                sh 'hostname'
                sh 'pwd'
                ...
            }
        }
        ...
        stage('History') {
            steps {
                sh 'history -a'
            }
        }
    }
    post {
        ...
    }
}

但这不起作用:

Console Output
...
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Tear Down)
[Pipeline] sh
+ history -a
/path/to/project-root@tmp/durable-66ba15cc/script.sh: 1: history: not found
[Pipeline] }
...

hostnamelspwd 等其他 Linux 命令运行良好。

为什么history 会出错?如何在管道的上下文中存储 Jenkins 调用的 shell 命令?

【问题讨论】:

  • 为什么?因为每个sh 步骤都会创建自己的shell 会话,该会话会在函数调用返回时被丢弃。如何? Maybe this 然后过滤 Jenkins 日志中以“+”开头的消息。

标签: shell jenkins command-line jenkins-pipeline command-line-interface


【解决方案1】:

我认为您遇到的特定错误只是因为您运行 sh 的代理没有可用的历史 cmd - history: not found

如果您可以存储 sh 命令...如果您只想要 sh 命令,我认为您需要写入您在开始时创建的文件,每次执行 sh 步骤时都写入该文件,或者您可以只使用管道日志文件(输出控制台)。

您可以找到here 一个关于管道位置或构建日志的线程,以防有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 2021-02-10
    相关资源
    最近更新 更多