【发布时间】: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] }
...
hostname、ls 或 pwd 等其他 Linux 命令运行良好。
为什么history 会出错?如何在管道的上下文中存储 Jenkins 调用的 shell 命令?
【问题讨论】:
-
为什么?因为每个
sh步骤都会创建自己的shell 会话,该会话会在函数调用返回时被丢弃。如何? Maybe this 然后过滤 Jenkins 日志中以“+”开头的消息。
标签: shell jenkins command-line jenkins-pipeline command-line-interface