Skip to content

Commit

Permalink
Merge branch 'JENKINS-25922'
Browse files Browse the repository at this point in the history
  • Loading branch information
daspilker committed Dec 29, 2014
2 parents 35aff11 + 9cc7b5c commit 36ff46b
Show file tree
Hide file tree
Showing 9 changed files with 633 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ And finally, if you want to get more involved, [here's how...](https://github.co
* Added support for the [Credentials Binding Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin)
* Added support for the [HTTP Request Plugin](https://wiki.jenkins-ci.org/display/JENKINS/HTTP+Request+Plugin)
* Added support for the [Build Monitor Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Build+Monitor+Plugin)
* Added support for the [Publish Over SSH Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin)
* Enhanced support for the [Config File Provider Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin)
* Added allow missing option for the [HTML Publisher Plugin](https://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin)
* Added clone timeout option for the [Git Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin)
Expand Down
1 change: 1 addition & 0 deletions docs/Job-DSL-Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ job(Map<String, ?> arguments = [:]) {
phase(String name, Closure phaseClosure = null)
phase(String name, String continuationConditionArg, Closure phaseClosure)
prerequisite(String projectList = '', boolean warningOnly = false) // since 1.19
publishOverSsh(Closure publishOverSshClosure) // since 1.28
rake(Closure rakeClosure = null) // since 1.25
rake(String tasksArg, Closure rakeClosure = null) // since 1.25
remoteTrigger(String remoteJenkinsName, String jobName,
Expand Down
91 changes: 91 additions & 0 deletions docs/Job-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,97 @@ sbt(/*standard parameters here*/) {
}
```

## Publish Over SSH

```groovy
job {
steps {
publishOverSsh {
server(String name) {
verbose(boolean verbose = true)
credentials(String username) {
pathToKey(String pathToKey)
key(String key)
}
retry(int retries = 0, int delay = 10000)
label(String label)
transferSet {
sourceFiles(String sourceFiles)
execCommand(String execCommand)
removePrefix(String prefix)
remoteDirectory(String remoteDirectory)
excludeFiles(String excludeFiles)
patternSeparator(String patternSeparator)
noDefaultExcludes(boolean noDefaultExcludes = true)
makeEmptyDirs(boolean makeEmptyDirs = true)
flattenFiles(boolean flattenFiles = true)
remoteDirIsDateFormat(boolean remoteDirIsDateFormat = true)
execTimeout(long execTimeout)
execInPty(boolean execInPty = true)
}
}
continueOnError(boolean continueOnError = true)
failOnError(boolean failOnError = true)
alwaysPublishFromMaster(boolean alwaysPublishFromMaster = true)
parameterizedPublishing(String parameterName)
}
}
}
```

Send artifacts to an SSH server (using SFTP) and/or execute commands over SSH. Requires the
[Publish Over SSH Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin).

Encrypted keys are currently not supported on job level, use the global configuration instead.

Examples:

```groovy
// Basic step
job {
steps {
publishOverSsh {
server('server-name') {
transferSet {
sourceFiles('file')
}
}
}
}
}
// Using parameter to match server label
job {
steps {
publishOverSsh {
server('my-server-01') {
credentials('user01') {
pathToKey('path01')
}
label('server-01')
transferSet {
sourceFiles('files')
execCommand('command')
}
}
server('my-server-02') {
credentials('user2') {
key('key')
}
label('server-02')
transferSet {
sourceFiles('files2')
execCommand('command2')
}
}
parameterizedPublishing('PARAMETER')
}
}
}
```

(since 1.28)

## Rake

```groovy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package javaposse.jobdsl.dsl.helpers.step

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.ContextHelper
import javaposse.jobdsl.dsl.DslContext

import static com.google.common.base.Preconditions.checkArgument

class PublishOverSshContext implements Context {
final List<PublishOverSshServerContext> servers = []
boolean continueOnError
boolean failOnError
boolean alwaysPublishFromMaster
String parameterName

void continueOnError(boolean continueOnError = true) {
this.continueOnError = continueOnError
}

void failOnError(boolean failOnError = true) {
this.failOnError = failOnError
}

void alwaysPublishFromMaster(boolean alwaysPublishFromMaster = true) {
this.alwaysPublishFromMaster = alwaysPublishFromMaster
}

void parameterizedPublishing(String parameterName) {
this.parameterName = parameterName
}

void server(String name, @DslContext(PublishOverSshServerContext) Closure serverClosure) {
PublishOverSshServerContext serverContext = new PublishOverSshServerContext(name)
ContextHelper.executeInContext(serverClosure, serverContext)

checkArgument(!serverContext.transferSets.empty, "At least 1 transferSet must be configured for ${name}")

servers << serverContext
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package javaposse.jobdsl.dsl.helpers.step

import javaposse.jobdsl.dsl.Context

class PublishOverSshCredentialsContext implements Context {
final String username
String pathToKey
String key

PublishOverSshCredentialsContext(String username) {
this.username = username
}

void pathToKey(String pathToKey) {
this.pathToKey = pathToKey
}

void key(String key) {
this.key = key
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package javaposse.jobdsl.dsl.helpers.step

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.ContextHelper
import javaposse.jobdsl.dsl.DslContext

import static com.google.common.base.Preconditions.checkArgument
import static com.google.common.base.Strings.isNullOrEmpty

class PublishOverSshServerContext implements Context {
final String name
final List<PublishOverSshTransferSetContext> transferSets = []
boolean verbose
String label
boolean retry
long retries
long delay
PublishOverSshCredentialsContext credentials

PublishOverSshServerContext(String name) {
this.name = name
}

void verbose(boolean verbose = true) {
this.verbose = verbose
}

void label(String label) {
this.label = label
}

void retry(int retries = 0, int delay = 10000) {
this.retry = true
this.retries = retries
this.delay = delay
}

void credentials(String username, @DslContext(PublishOverSshCredentialsContext) Closure credentialsClosure) {
PublishOverSshCredentialsContext credentialsContext = new PublishOverSshCredentialsContext(username)
ContextHelper.executeInContext(credentialsClosure, credentialsContext)

credentials = credentialsContext
}

void transferSet(@DslContext(PublishOverSshTransferSetContext) Closure transferSetClosure) {
PublishOverSshTransferSetContext transferSetContext = new PublishOverSshTransferSetContext()
ContextHelper.executeInContext(transferSetClosure, transferSetContext)

checkArgument(
!isNullOrEmpty(transferSetContext.sourceFiles) || !isNullOrEmpty(transferSetContext.execCommand),
'sourceFiles or execCommand must be specified'
)

transferSets << transferSetContext
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package javaposse.jobdsl.dsl.helpers.step

import javaposse.jobdsl.dsl.Context

class PublishOverSshTransferSetContext implements Context {
String sourceFiles
String execCommand
String removePrefix
String remoteDirectory
String excludeFiles
String patternSeparator = '[, ]+'
boolean noDefaultExcludes
boolean makeEmptyDirs
boolean flattenFiles
boolean remoteDirIsDateFormat
long execTimeout = 120000
boolean execInPty

void sourceFiles(String sourceFiles) {
this.sourceFiles = sourceFiles
}

void execCommand(String execCommand) {
this.execCommand = execCommand
}

void removePrefix(String prefix) {
this.removePrefix = prefix
}

void remoteDirectory(String remoteDirectory) {
this.remoteDirectory = remoteDirectory
}

void excludeFiles(String excludeFiles) {
this.excludeFiles = excludeFiles
}

void patternSeparator(String patternSeparator) {
this.patternSeparator = patternSeparator
}

void noDefaultExcludes(boolean noDefaultExcludes = true) {
this.noDefaultExcludes = noDefaultExcludes
}

void makeEmptyDirs(boolean makeEmptyDirs = true) {
this.makeEmptyDirs = makeEmptyDirs
}

void flattenFiles(boolean flattenFiles = true) {
this.flattenFiles = flattenFiles
}

void remoteDirIsDateFormat(boolean remoteDirIsDateFormat = true) {
this.remoteDirIsDateFormat = remoteDirIsDateFormat
}

void execTimeout(long execTimeout) {
this.execTimeout = execTimeout
}

void execInPty(boolean execInPty = true) {
this.execInPty = execInPty
}
}
Loading

0 comments on commit 36ff46b

Please sign in to comment.