Jenkins 的 SSH Pipeline Steps 插件的 sshPut 功能在传输单个文件时如何不复制本地目录结构?

159 天前
 huangsijun17

将本地 "test-dir" 目录下的 "demo.txt" 文件推送到远程 "/tmp/ssh-test/" 目录下。"test-dir" 目录会自动创建。无法将 "demo.txt" 直接放入 "/tmp/ssh-test/" 目录中。 即使我将工作目录切换到 "test-dir",仍然无法实现。

示例脚本

pipeline {
 agent any
 stages {
  stage ('Test') {
   steps {
    sh 'mkdir -p test-dir && echo "test" > test-dir/demo.txt' // 创建本地目录结构
    dir ('test-dir') {
     sshPut remote: [host: 'remote-ip', user: 'user', password: 'pass'],
       from: '.', into: '/tmp/ssh-test' // 传输当前目录
    }
    sshCommand remote: [host: 'remote-ip', user: 'user', password: 'pass'],
       command: 'ls -l /tmp/ssh-test' // 验证远程路径
   }
  }
 }
}

如何修改来讲文件应直接复制到指定的路径: /tmp/ssh-test/demo.txt

1297 次点击
所在节点    程序员
6 条回复
ZeekChatCom
159 天前
from 由 . 改为 demo.txt
defunct9
158 天前
弄一大堆插件,不如一套 shell 来的痛快
huangsijun17
158 天前
@defunct9 #2 被迫使用密码,我难不成全部用回 sshpass ?
huangsijun17
158 天前
@ZeekChatCom #1
1. 依然带路径。
2. 实际场景下,该路径下不止一个文件,我用了“filterRegex”的正则表达式,所以 from 要路径。
ZeekChatCom
158 天前
@huangsijun17

试试 remote 中添加 fileTransfer: 'scp', 有人这样说,我没试过。

实在不行,再 sshCommand 中 mv 移动一下
defunct9
158 天前
用 sshpass 有啥不好,看着这屎一样的 pipleline, groovy ,就很恶心。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1122986

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX