Jenkins Pipeline 流水线 - 上传文件 Publish over SSH 执行命令

jenkins,pipeline,流水线,上传,文件,publish,over,ssh,执行命令 · 浏览次数 : 3011

小编点评

**生成 sshPublisher 代码时选择:Verbose output in console** 生成 sshPublisher 代码时需要选择 **Verbose output in console**选项。这会打印远程服务上的日志pipeline,包括上传文件的详细过程。 **其他选项的含义:** * `usePromotionTimestamp`: 是否使用构建时间作为文件名的一部分。 * `useWorkspaceInPromotion`: 是否将构建结果存储在工作空间中。 * `verbose`: 是否打印详细的命令输出。 * `skipSecurityCheck`: 是否忽略安全检查。

正文

Jenkins Pipeline 流水线 - 上传文件 Publish over SSH 执行命令

Jenkins插件安装

  • Publish over SSH

系统配置

image
image
image

生成代码

sshPublisher: Send build artifacts over SSH
需要在 生成 sshPublisher 代码时选择:Verbose output in console,否则不会打印远程服务上的日志
image
image
image

pipeline {
    agent any
 
    stages {  
        stage('上传文件') { 
            steps {
			    //先上传文件,后执行命令,命令和源文件,两者必须有一个有值
                sshPublisher(publishers: [sshPublisherDesc(configName: 'DockerPublishSSH', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'docker --version', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'PipelineDemo', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/demojenkins*.jar')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
                echo 'Credentials SUCCESS'
            }
        } 
    }
}

image
image

打印远程日志

Publish Over SSH 插件打印远程ssh的日志,需要在 生成 sshPublisher 代码时选择:Verbose output in console
image
image

如果出现 SSH: Transferred 0 file(s)
看本地的文件路径是否正确 widnows 下注意用 \ 如果用 / 可能导致文件上传时找不到文件

与Jenkins Pipeline 流水线 - 上传文件 Publish over SSH 执行命令相似的内容: