• Stars
    star
    273
  • Rank 145,097 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jenkins pipeline steps which provides SSH facilities such as command execution or file transfer for continuous delivery.

SSH Pipeline Steps

Jenkins

Build License Wiki ssh steps plugin

Jenkins pipeline steps which provides SSH facilities such as command execution or file transfer for continuous delivery. It internally uses the library of Groovy SSH.

Read more about the YAML extension of this plugin at this blog post


Configuration

Remote

Most of the steps in this plugin require a common step variable called remote, which is Map of remote node settings such as user name, password and so on. Here is list of all possible keys that can be set.

Key Type Description

name

String, Mandatory

Remote name, usually this is same as host name.

host

String, Mandatory

Hostname or IP address of the remote host.

port

int

Port. Defaults to port 22.

user

String, Mandatory

User name.

allowAnyHosts

boolean

If this is true, knownHosts is optional. Defaults to false.

knownHosts

String, Mandatory

Known hosts file for host key checking.

password

String, one of password, identity or identityFile is required

Password for password authentication.

identity

String, one of password, identity or identityFile is required

Private key for public-key authentication.

identityFile

String, one of password, identity or identityFile is required

Private key file name for public-key authentication.

passphrase

String

Pass-phrase for the private key.

agent

boolean

If this is true, Putty Agent or ssh-agent is used on authentication. Defaults to false.

timeoutSec

int

Connection timeout and socket read timeout. Defaults to 0 (OS default).

retryCount

int

Retry count to establish connection. Defaults to 0 (no retry).

retryWaitSec

int

Interval time between each retries. Defaults to 0 (immediately).

keepAliveSec

int

Interval time of keep alive messages sent to the remote host. Defaults to 60 seconds.

agentForwarding

boolean

If this is true, the agent forwarding is requested on the command execution. Defaults to false.

fileTransfer

String

File transfer method, that is SFTP or SCP. Defaults to SFTP.

encoding

String

Encoding of input and output on the command or shell execution. Defaults to UTF-8.

proxy

Proxy, refer below.

If this is set, the proxy server is used to reach the remote host. Defaults to no proxy.

gateway

Remote

Gateway remote host. If this is set, the port-forwarding tunnel is used to reach the remote host. Defaults to no gateway.

appendName

boolean

If this is true, name is prefixed to each line in the log output. New format: name|log.

logLevel

String

Defaults to SEVERE

Possible values, refer to java logging levels

  • SEVERE (highest value)

  • WARNING

  • INFO

  • CONFIG

  • FINE

  • FINER

  • FINEST (lowest value)

pty

boolean

If this is true, a PTY (pseudo-terminal) is allocated on the command execution. Defaults to false.

Proxy

Key Type Description

name

String, Mandatory

Proxy name

host

String, Mandatory

Hostname or IP address of the proxy server.

port

int, Mandatory

Port of the proxy server.

type

String, Mandatory

Type of the proxy server: SOCKS or HTTP.

user

String

User name of the proxy server.

password

String

Password of the proxy server.

socksVersion

int

Protocol version when using SOCKS: 4 or 5. Defaults to 5.

Pipeline Steps

The following pipeline steps are available with the initial version of this plugin.

sshCommand

This step executes given command on remote node and responds with output.

Input

Key Type Description

remote

Remote, Mandatory, Refer to the Remote config for more details.

Host config to run the command on.

command

String, Mandatory

Shell command to run. Appending sudo is optional when sudo is true.

sudo

boolean, default: false.

Interactively supplies the password, not required for password less sudo commands.

sshCommand with sudo:true param also requires pty:true on remote config with this upgrade. (This is only applicable for few platforms like Linux so apply this accordingly.)

failOnError

boolean, default: true.

If this is false, no job failure would occur though there is an error while running the command.

dryRun

boolean, default: false

If this is true, no actual connection or operation is performed.

Example

node {
  def remote = [:]
  remote.name = 'test'
  remote.host = 'test.domain.com'
  remote.user = 'root'
  remote.password = 'password'
  remote.allowAnyHosts = true
  stage('Remote SSH') {
    sshCommand remote: remote, command: "ls -lrt"
    sshCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
  }
}

sshScript

This step executes given script(file) on remote node and responds with output.

Input

Key Type Description

remote

Remote, Mandatory, Refer to the Remote config for more details.

Host config to run the command on.

script

String, Mandatory

Script file name from the workspace, current this doesn’t support script with arguments. For that option you would need to copy over the file to remote node and run it as a command.

failOnError

boolean, default: true.

If this is false, no job failure would occur though there is an error while running the command.

dryRun

boolean, default: false

If this is true, no actual connection or operation is performed.

Example

node {
  def remote = [:]
  remote.name = 'test'
  remote.host = 'test.domain.com'
  remote.user = 'root'
  remote.password = 'password'
  remote.allowAnyHosts = true
  stage('Remote SSH') {
    writeFile file: 'abc.sh', text: 'ls -lrt'
    sshScript remote: remote, script: "abc.sh"
  }
}

sshPut

Put a file or directory into the remote host.

Input

Key Type Description

remote

Remote, Mandatory, Refer to the Remote config for more details.

Host config to run the command on.

from

String, Mandatory

file or directory path from the workspace.

into

String, Mandatory

file or directory path on the remote node.

filterBy

String, Optional, Defaults to name.

Put files by a file filter. Possible values are params on the java File object.

filterRegex

String, Optional.

Put files by a file regex (Groovy syntax). Example: /\.xml$/ - Puts all xml files.

failOnError

boolean, default: true.

If this is false, no job failure would occur though there is an error while running the command.

dryRun

boolean, default: false

If this is true, no actual connection or operation is performed.

Example

node {
  def remote = [:]
  remote.name = 'test'
  remote.host = 'test.domain.com'
  remote.user = 'root'
  remote.password = 'password'
  remote.allowAnyHosts = true
  stage('Remote SSH') {
    writeFile file: 'abc.sh', text: 'ls -lrt'
    sshPut remote: remote, from: 'abc.sh', into: '.'
  }
}

sshGet

Get a file or directory from the remote host.

Input

Key Type Description

remote

Remote, Mandatory, Refer to the Remote config for more details.

Host config to run the command on.

from

String, Mandatory

file or directory path from the remote node.

into

String, Mandatory

file or directory path on current workspace.

filterBy

String, Optional, Defaults to name.

Get files by a file filter. Possible values are params on the java File object.

filterRegex

String, Optional.

Get files by a file regex (Groovy syntax). Example: /\.xml$/ - Gets all xml files.

failOnError

boolean, default: true.

If this is false, no job failure would occur though there is an error while running the command.

dryRun

boolean, default: false

If this is true, no actual connection or operation is performed.

Example

node {
  def remote = [:]
  remote.name = 'test'
  remote.host = 'test.domain.com'
  remote.user = 'root'
  remote.password = 'password'
  remote.allowAnyHosts = true
  stage('Remote SSH') {
    sshGet remote: remote, from: 'abc.sh', into: 'abc_get.sh', override: true
  }
}

sshRemove

Remove a file or directory on the remote host.

Input

Key Type Description

remote

Remote, Mandatory, Refer to the Remote config for more details.

Host config to run the command on.

path

String, Mandatory

file or directory path on the remote node

failOnError

boolean, default: true.

If this is false, no job failure would occur though there is an error while running the command.

dryRun

boolean, default: false

If this is true, no actual connection or operation is performed.

Example

node {
  def remote = [:]
  remote.name = 'test'
  remote.host = 'test.domain.com'
  remote.user = 'root'
  remote.password = 'password'
  remote.allowAnyHosts = true
  stage('Remote SSH') {
    sshRemove remote: remote, path: "abc.sh"
  }
}

Examples

withCredentials

An example how these steps can leverage withCredentials to read private key from Jenkins credentials store.

def remote = [:]
remote.name = "node-1"
remote.host = "10.000.000.153"
remote.allowAnyHosts = true

node {
    withCredentials([sshUserPrivateKey(credentialsId: 'sshUser', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
        remote.user = userName
        remote.identityFile = identity
        stage("SSH Steps Rocks!") {
            writeFile file: 'abc.sh', text: 'ls'
            sshCommand remote: remote, command: 'for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done'
            sshPut remote: remote, from: 'abc.sh', into: '.'
            sshGet remote: remote, from: 'abc.sh', into: 'bac.sh', override: true
            sshScript remote: remote, script: 'abc.sh'
            sshRemove remote: remote, path: 'abc.sh'
        }
    }
}

Classic View:

ExampleWithCredentials

Blue Ocean View:

ExampleWithCredentialsBlueOcean

Disclaimer

Please don’t hesitate to log a JIRA or github pull request if you need any help or if you can be of help with this plugin :). Refer to the contribution guide for more information.

License

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the
License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
“AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 language governing permissions and limitations under the License.

More Repositories

1

jenkins

Jenkins automation server
Java
21,381
star
2

docker

Docker official jenkins repo
Dockerfile
6,144
star
3

pipeline-examples

A collection of examples, tips and tricks and snippets of scripting for the Jenkins Pipeline plugin
Groovy
4,117
star
4

blueocean-plugin

Blue Ocean is a reboot of the Jenkins CI/CD User Experience
Java
2,872
star
5

configuration-as-code-plugin

Jenkins Configuration as Code Plugin
Java
2,521
star
6

kubernetes-plugin

Jenkins plugin to run dynamic agents in a Kubernetes/Docker environment
Java
2,206
star
7

job-dsl-plugin

A Groovy DSL for Jenkins Jobs - Sweeeeet!
Groovy
1,851
star
8

pipeline-plugin

Obsolete home for Pipeline plugins
1,711
star
9

JenkinsPipelineUnit

Framework for unit testing Jenkins pipelines
Groovy
1,426
star
10

gitlab-plugin

A Jenkins plugin for interfacing with GitLab
Java
1,418
star
11

jenkinsfile-runner

A command line tool to run Jenkinsfile as a function
Java
1,114
star
12

java-client-api

A Jenkins API client for Java
Java
888
star
13

jenkins-scripts

Scripts in Groovy, shell, Ruby, Python, whatever for managing/interacting with Jenkins
Groovy
880
star
14

build-monitor-plugin

Jenkins Build Monitor Plugin
Java
722
star
15

slack-plugin

A Jenkins plugin for posting notifications to a Slack channel
Java
664
star
16

git-plugin

Git repository access for Jenkins jobs
Java
660
star
17

pipeline-model-definition-plugin

Groovy
557
star
18

ghprb-plugin

github pull requests builder plugin for Jenkins
Java
495
star
19

docker-workflow-plugin

Jenkins plugin which allows building, testing, and using Docker images from Jenkins Pipeline projects.
Java
492
star
20

docker-plugin

Jenkins Cloud Plugin that uses Docker
Java
482
star
21

docker-inbound-agent

Docker image for a Jenkins agent which can connect to Jenkins using TCP or Websocket protocols
PowerShell
466
star
22

helm-charts

Jenkins helm charts
Mustache
448
star
23

pipeline-aws-plugin

Jenkins Pipeline Step Plugin for AWS
Java
423
star
24

jenkins.rb

Deprecated, see https://www.jenkins.io/jep/7
Ruby
394
star
25

generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
Java
377
star
26

email-ext-plugin

Jenkins Email Extension Plugin
Java
338
star
27

dingtalk-plugin

Dingtalk for jenkins
Java
336
star
28

warnings-ng-plugin

Jenkins Warnings Plugin - Next Generation
Java
323
star
29

plugin-installation-manager-tool

Plugin Manager CLI tool for Jenkins
Java
301
star
30

mesos-plugin

Mesos Cloud Jenkins Plugin
Java
291
star
31

github-plugin

Jenkins GitHub plugin
Java
286
star
32

ec2-plugin

Jenkins ec2 plugin
Java
282
star
33

ansicolor-plugin

Jenkins ANSI Color Plugin
Java
253
star
34

pipeline-utility-steps-plugin

Small, miscellaneous, cross platform utility steps for Jenkins Pipeline jobs.
Java
237
star
35

docker-agent

Base Docker image for Jenkins Agents
PowerShell
231
star
36

ansible-plugin

Jenkins Ansible plugin
Java
223
star
37

workflow-cps-global-lib-plugin

Java
223
star
38

lib-file-leak-detector

Java agent that detects file handle leak
Java
217
star
39

hashicorp-vault-plugin

Jenkins plugin to populate environment variables from secrets stored in HashiCorp's Vault.
Java
214
star
40

bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
Java
213
star
41

remoting

Jenkins Remoting module
Java
212
star
42

workflow-aggregator-plugin

211
star
43

gerrit-trigger-plugin

Java
209
star
44

android-emulator-plugin

Android Emulator plugin for Jenkins
Java
207
star
45

docker-slaves-plugin

A Jenkins plugin to run builds inside Docker containers
Java
205
star
46

pipeline-stage-view-plugin

Visualizes Jenkins pipelines
JavaScript
204
star
47

jenkinsfile-runner-github-actions

Jenkins single-shot pipeline execution in a GitHub Action POC
Shell
199
star
48

github-branch-source-plugin

GitHub Branch Source Plugin
Java
193
star
49

amazon-ecs-plugin

Amazon EC2 Container Service Plugin for Jenkins
Java
193
star
50

trilead-ssh2

Patched trilead-ssh2 used in Jenkins
Java
193
star
51

cucumber-reports-plugin

Jenkins plugin to generate cucumber-jvm reports
Java
192
star
52

docker-build-publish-plugin

Java
192
star
53

performance-plugin

Performance Test Running and Reporting for Jenkins CI
Java
188
star
54

jira-plugin

Jenkins jira plugin
Java
168
star
55

gitea-plugin

This plugin provides the Jenkins integration for Gitea.
Java
168
star
56

embeddable-build-status-plugin

Embed build status of Jenkins jobs in web pages
Java
167
star
57

stashnotifier-plugin

A Jenkins Plugin to notify Atlassian Stash|Bitbucket of build results
Java
166
star
58

docker-ssh-agent

Docker image for Jenkins agents connected over SSH
PowerShell
162
star
59

workflow-cps-plugin

Java
160
star
60

http-request-plugin

This plugin does a request to an url with some parameters.
Java
154
star
61

stapler

Stapler web framework
Java
154
star
62

kubernetes-pipeline-plugin

Kubernetes Pipeline is Jenkins plugin which extends Jenkins Pipeline to provide native support for using Kubernetes pods, secrets and volumes to perform builds
Java
154
star
63

tfs-plugin

Jenkins tfs plugin
Java
145
star
64

jep

Jenkins Enhancement Proposals
Shell
144
star
65

kubernetes-cd-plugin

A Jenkins plugin to deploy to Kubernetes cluster
Java
140
star
66

jacoco-plugin

Jenkins JaCoCo Plugin
Java
139
star
67

qy-wechat-notification-plugin

企业微信Jenkins构建通知插件
Java
138
star
68

swarm-plugin

Jenkins swarm plugin
Java
133
star
69

git-client-plugin

Git client API for Jenkins plugins
Java
130
star
70

subversion-plugin

Jenkins subversion plugin
Java
126
star
71

dependency-check-plugin

Jenkins plugin for OWASP Dependency-Check. Inspects project components for known vulnerabilities (e.g. CVEs).
Java
125
star
72

role-strategy-plugin

Jenkins Role-Strategy plugin
Java
120
star
73

groovy-sandbox

(Deprecated) Compile-time transformer to run Groovy code in a restrictive sandbox
Java
120
star
74

jenkins-design-language

Styles, assets, and React classes for Jenkins Design Language
TypeScript
116
star
75

acceptance-test-harness

Acceptance tests cases for Jenkins and its plugins based on selenium and docker.
Java
116
star
76

scm-sync-configuration-plugin

Jenkins scm-sync-configuration plugin
Java
116
star
77

gitlab-branch-source-plugin

A Jenkins Plugin for GitLab Multibranch Pipeline jobs and Folder Organization
Java
115
star
78

git-parameter-plugin

Jenkins plugin for chosing Revision / Tag before build
Java
115
star
79

publish-over-ssh-plugin

Java
114
star
80

pipeline-as-yaml-plugin

Jenkins Pipeline As Yaml Plugin
Java
114
star
81

selenium-plugin

Jenkins selenium plugin
Java
112
star
82

docker-build-step-plugin

Java
111
star
83

code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
Java
111
star
84

jira-trigger-plugin

Triggers a build when a certain condition is matched in JIRA
Groovy
111
star
85

cobertura-plugin

Jenkins cobertura plugin
Java
110
star
86

gradle-plugin

Jenkins gradle plugin
Java
109
star
87

credentials-plugin

Provides Jenkins with extension points to securely store, manage, and bind credentials data to other Jenkins plugins, builds, pipelines, etc.
Java
107
star
88

jira-steps-plugin

Jenkins pipeline steps for integration with JIRA.
Java
104
star
89

artifactory-plugin

Jenkins artifactory plugin
Java
104
star
90

build-flow-plugin

A plugin to manage job orchestration
Groovy
103
star
91

throttle-concurrent-builds-plugin

Java
101
star
92

github-oauth-plugin

Jenkins authentication plugin using GitHub OAuth as the source.
Java
99
star
93

pipeline-graph-view-plugin

Java
99
star
94

promoted-builds-plugin

Jenkins Promoted Builds Plugin
Java
96
star
95

ssh-slaves-plugin

SSH Build Agents Plugin for Jenkins
Java
96
star
96

github-pr-coverage-status-plugin

Nice test coverage icon for your pull requests just from Jenkins
Java
93
star
97

jenkins-test-harness

Unit test framework for Jenkins core and its plugins
Java
92
star
98

opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
Java
90
star
99

localization-zh-cn-plugin

Chinese Localization for Jenkins
HTML
89
star
100

workflow-remote-loader-plugin

Load Pipeline scripts from remote locations (e.g. Git) - replaced by Pipeline: Groovy Libraries plugin
Java
88
star