Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit 55caec6

Browse files
authored
Merge pull request #32 from sap-production/openSource
Enables Jenkins 2.x Pipelines
2 parents 6e15739 + e3e6512 commit 55caec6

File tree

73 files changed

+5076
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5076
-1244
lines changed

Jenkinsfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Builds a module using https://github.com/jenkins-infra/pipeline-library
2+
// Requirements:
3+
// - agents with label 'linux' and 'windows'
4+
// - tools with label 'jdk8' and 'mvn'
5+
// - latest Pipeline plugins, 'Timestamper' plugin
6+
// - recommended to use this Jenkinsfile with 'Multibranch Pipeline' plugin
7+
8+
buildPlugin()

README.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,7 @@ This plugin also has support for build authorization tokens (as defined [here](h
1414

1515
Please take a look at the [change log](CHANGELOG.md) for a complete list of features and what not.
1616

17-
18-
###Screenshots
19-
System configuration option
20-
21-
![System onfiguration option](screenshots/1-system-settings.png)
22-
23-
24-
Job setup options
25-
26-
![select from drop-down](screenshots/2-build-configuration-1.png)
27-
28-
![Job setup options](screenshots/3-build-configuration-2.png)
29-
30-
31-
####Current Limitations
32-
1. ~~Does not play well with [Build Token Root Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin) URL formats.~~ (added with [this commit](https://github.com/morficus/Parameterized-Remote-Trigger-Plugin/commit/f687dbe75d1c4f39f7e14b68220890384d7c5674) )
33-
2. ~~No username/password authentication, must use a 'build authorization token'.~~ (added with [this commit](https://github.com/morficus/Parameterized-Remote-Trigger-Plugin/commit/a23ade0add621830e85eb228990a95658e239b80) )
34-
3. ~~Follows a "fire & forget" model when triggering the remote build, which means that we don't know the status of the remote build, only if the request was successful or not.~~ (added with [this commit](https://github.com/morficus/Parameterized-Remote-Trigger-Plugin/commit/d32c69d0033aefda382c55e9394ebab8d1da10ae) thanks to [@timbrown5](https://github.com/timbrown5))
17+
## Usage
18+
1. [System configuration options](README_SystemConfiguration.md)<br>
19+
2. [Job setup options](README_JobConfiguration.md)<br>
20+
3. [Pipeline setup options](README_PipelineConfiguration.md)

README_JobConfiguration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Job setup options
2+
3+
Select `Build` > `Add build step` > `Trigger a remote parameterized job`
4+
5+
![select from drop-down](screenshots/2-build-configuration-1.png)
6+
7+
You can select a globally configured remote server and only specify a job name here.
8+
The full URL is calculated based on the remote server, the authentication is taken from the global configuration.
9+
However it is possible to override the Jenkins base URL (or set the full Job URL) and override credentials used for authentication.
10+
11+
![Job setup options](screenshots/3-build-configuration-2.png)
12+
13+
You can also specify the full job URL and use only the authentication from the global configuration or specify the authentication per job.
14+
15+
![Job setup options](screenshots/3-build-configuration-2b.png)
16+
17+
18+
# Support of Folders on Remote Jenkins
19+
[See here for more information](README_PipelineConfiguration.md#user-content-folders)

README_PipelineConfiguration.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Pipeline setup options
2+
3+
- [Defaults](#user-content-defaults)
4+
- [Remote Server Configuration](#user-content-server)
5+
- [Authentication](#user-content-authentication)
6+
- [The Handle Object](#user-content-handle)
7+
- [Blocking vs. Non-Blocking](#user-content-blockingnonblocking)
8+
- [Blocking usage (recommended)](#user-content-blocking)
9+
- [Non-blocking usage](#user-content-nonblocking)
10+
- [Support of Folders on Remote Jenkins](#user-content-folders)
11+
12+
The `triggerRemoteJob` pipeline step triggers a job on a remote Jenkins. This command is also available in the Jenkins Pipeline Syntax Generator:
13+
14+
You can select a globally configured remote server and only specify a job name here.
15+
The full URL is calculated based on the remote server, the authentication is taken from the global configuration.
16+
However it is possible to override the Jenkins base URL (or set the full Job URL) and override credentials used for authentication.
17+
18+
![Pipeline Syntax Generator](screenshots/pipelineSyntaxGenerator.png)
19+
20+
You can also specify the full job URL and use only the authentication from the global configuration or specify the authentication per job.
21+
22+
![Pipeline Syntax Generator](screenshots/pipelineSyntaxGenerator2.png)
23+
24+
25+
<div id="defaults"/>
26+
27+
## Defaults
28+
The simplest way to trigger a job is:
29+
```
30+
def handle = triggerRemoteJob job: 'https://myjenkins:8080/job/JobWithoutParams'
31+
echo 'Remote Status: ' + handle.getBuildStatus().toString()
32+
```
33+
34+
If the job has parameters:
35+
```
36+
def handle = triggerRemoteJob job: 'https://myjenkins:8080/job/JobWithParams', parameters: 'param1=abc\nparam2=xyz'
37+
```
38+
39+
If authentication is required:
40+
```
41+
def handle = triggerRemoteJob job: 'https://myjenkins:8080/job/JobWithoutParams', auth: TokenAuth(apiToken: '<theApiToken>', userName: '<userName>')
42+
```
43+
44+
45+
The pipeline will wait/block until the remote build finished.
46+
47+
48+
<div id="server"/>
49+
50+
## Remote Server Configuration
51+
52+
:information_source: You can configure jobs/pipelines also without any global configuration.
53+
54+
The remote Jenkins server containing the target job(s) can be configured in different ways.
55+
- **Jenkins System Configuration**<br>
56+
Remote servers can be configured in the [Jenkins System Configuration](README_SystemConfiguration.md) and referenced in Pipelines by their name. The server configuration can also include authentication settings.<br>
57+
`triggerRemoteJob remoteJenkinsName: 'remoteJenkins' ...`
58+
- **Override Server URL**<br>
59+
On Pipeline level the URL can be set/overridden with parameter `remoteJenkinsUrl`.<br>
60+
`triggerRemoteJob remoteJenkinsUrl: 'https://myjenkins:8080' ...`<br>
61+
If combined with `remoteJenkinsName` only the URL of the globally configured server will be overridden, the other settings like authentication will be used from the global configuration.<br>
62+
`triggerRemoteJob remoteJenkinsName: 'remoteJenkins', remoteJenkinsUrl: 'https://myjenkins:8080' ...`<br>
63+
- **Full Job URL**<br>
64+
It is also possible to configure the full job URL instead of the job name only and the remote Jenkins server root URL.<br>
65+
`triggerRemoteJob job: 'https://myjenkins:8080/job/MyJob' ...`<br>
66+
67+
:information_source: If the remote Jenkins uses folders please [read this](#user-content-folders).
68+
69+
<div id="authentication"/>
70+
71+
## Authentication
72+
Authentication can be configured globally in the system configuration or set/overridden for each pipeline via the `auth` parameter.
73+
74+
The following authentication types are available:
75+
- **Token Authentication** The specified user id and Jenkins API token is used.<br>
76+
```auth: TokenAuth(apiToken: '<theApiToken>', userName: '<userName>')```
77+
- **Credentials Authentication** The specified Jenkins Credentials are used. This can be either user/password or user/API Token.<br>
78+
```auth: CredentialsAuth(credentials: '<credentialId>')```
79+
- **No Authentication** No Authorization header will be sent, independent of the global 'remote host' settings.<br>
80+
```auth: NoneAuth()```
81+
82+
**Note:** *Jenkins API Tokens* are recommended since, if stolen, they allow access only to a specific Jenkins
83+
while user and password typically provide access to many systems.
84+
85+
86+
87+
<div id="handle"/>
88+
89+
## The Handle Object
90+
The `Handle` object provides the following methods:
91+
92+
- `String getJobName()` returns the remote job name
93+
- `URL getBuildUrl()` returns the remote build URL including the build number
94+
- `int getBuildNumber()` returns the remote build number
95+
- `BuildStatus getBuildStatus()` returns the current remote build status
96+
- `BuildStatus getBuildStatusBlocking()` waits for completion and returns the build result
97+
- `boolean isFinished()` true if the remote build finished
98+
- `boolean isQueued()` true if the job is queued but not yet running
99+
- `String toString()`
100+
- `Object readJsonFileFromBuildArchive(String filename)`<br>
101+
This is a convenience method to download and parse the specified JSON file (filename or relative path) from the build archive.
102+
This mechanism might be used by remote builds to provide return parameters.
103+
104+
```
105+
def handle = triggerRemoteJob blockBuildUntilComplete: true, ...
106+
def results = handle.readJsonFileFromBuildArchive('build-results.json')
107+
echo results.urlToTestResults //just an example
108+
```
109+
110+
The `BuildStatus` enum provides the following types and methods:
111+
112+
- Custom statuses: `UNKNOWN`, `NOT_STARTED`, `QUEUED`, `RUNNING`, if the remote job did not finish yet.
113+
- Jenkins Result statuses: `ABORTED`, `FAILURE`, `NOT_BUILT`, `SUCCESS`, `UNSTABLE`, if the remote job finished the status reflects the Jenkins build `Result`.
114+
- `boolean isJenkinsResult()`, true if the `BuildStatus` reflects a Jenkins `Result`.
115+
- `Result getJenkinsResult()`, the Jenkins `Result` if the status reflects one, null otherwise.
116+
- `String toString()`
117+
118+
119+
<div id="blockingnonblocking"/>
120+
121+
## Blocking vs. Non-Blocking
122+
The `triggerRemoteJob` command always returns a [`Handle`](#user-content-the-handle-object) object. This object can be used to track the status of the remote build (instead of using the environment variables like in the Job case).
123+
124+
There are two ways to use the command, in a blocking way (it will wait/block until the remote job finished) and in a non-blocking way (the handle is returned immediately and the remote status can be checked asynchronously).
125+
126+
<div id="blocking"/>
127+
128+
### Blocking usage (recommended)
129+
The recommended way to trigger jobs is in a blocking way. Set `blockBuildUntilComplete: true` to let the plugin wait
130+
until the remote build finished:
131+
```
132+
def handle = triggerRemoteJob(
133+
remoteJenkinsName: 'remoteJenkins',
134+
job: 'TheJob',
135+
parameters: 'a=b',
136+
blockBuildUntilComplete: true,
137+
...)
138+
echo 'Remote Status: ' + handle.getBuildStatus().toString()
139+
```
140+
141+
<div id="nonblocking"/>
142+
143+
### Non-blocking usage
144+
It is also possible to use it in a non-blocking way. Set `blockBuildUntilComplete: false` and the plugin directly
145+
returns the `handle` for further tracking the status:
146+
```
147+
def handle = triggerRemoteJob(
148+
remoteJenkinsName: 'remoteJenkins',
149+
job: 'TheJob',
150+
parameters: 'a=b',
151+
blockBuildUntilComplete: false,
152+
...)
153+
while( !handle.isFinished() ) {
154+
echo 'Current Status: ' + handle.getBuildStatus().toString();
155+
sleep 5
156+
}
157+
echo handle.getBuildStatus().toString();
158+
```
159+
160+
Even with `blockBuildUntilComplete: false` it is possible to wait synchronously until the remote job finished:
161+
```
162+
def handle = triggerRemoteJob blockBuildUntilComplete: false, ...
163+
def status = handle.getBuildStatusBlocking()
164+
```
165+
166+
:warning: Currently the plugin cannot log to the pipeline log directly if used in non-blocking mode. As workaround you can use `handle.lastLog()` after each command to get the log entries.
167+
168+
169+
<div id="folders"/>
170+
171+
# Support of Folders on Remote Jenkins
172+
173+
The Parameterized Remote Trigger plugin also supports the use of folders on the remote Jenkins server, for example if it uses the [`CloudBees Folders Plugin`](https://wiki.jenkins.io/display/JENKINS/CloudBees+Folders+Plugin) or the [`GitHub Branch Source Plugin`](https://plugins.jenkins.io/github-branch-source) (formerly [`GitHub Organization Folder Plugin`](https://wiki.jenkins.io/display/JENKINS/GitHub+Organization+Folder+Plugin))
174+
175+
Remote URLs with folders look like this
176+
```
177+
https://server:8080/job/Folder1/job/Folder2/job/TheJob
178+
```
179+
180+
Without folders it would only be `https://server:8080/job/TheJob`
181+
182+
To be able to trigger such jobs you have to either
183+
1. Specify the full Job URL as `Remote Job Name or URL`
184+
2. Specify the job fullname as `Remote Job Name or URL` + a globally configured [`Remote Host`](#user-content-server).<br>
185+
The jobs fullname in the example above would be 'Folder1/Folder2/TheJob'.
186+
187+
188+
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

README_SystemConfiguration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# System configuration options
2+
3+
The Parameterized Remote Trigger plugin can used without any global Jenkins system configuration.
4+
5+
However it might be useful to configure one or more remote server & credentials globally.
6+
From a job/pipeline this server can be referenced together with the job name, without the need to specify the full URL and authentication credentials. Still it is possible to specify or override each part on job/pipeline level.
7+
8+
![System onfiguration option](screenshots/1-system-settings.png)

pom.xml

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
<parent>
44
<groupId>org.jenkins-ci.plugins</groupId>
55
<artifactId>plugin</artifactId>
6-
<version>1.580</version>
6+
<version>3.5</version>
77
</parent>
88

9+
<properties>
10+
<jenkins.version>1.642.3</jenkins.version>
11+
<java.level>7</java.level>
12+
</properties>
13+
914
<artifactId>Parameterized-Remote-Trigger</artifactId>
10-
<version>2.2.3-SNAPSHOT</version>
15+
<version>3.0.0-SNAPSHOT</version>
1116
<packaging>hpi</packaging>
1217
<name>Parameterized Remote Trigger Plugin</name>
1318
<description>This plugin gives you the ability to trigger parameterized builds on a remote Jenkins server as part of your build.</description>
1419
<url>http://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Remote+Trigger+Plugin</url>
15-
20+
1621
<licenses>
1722
<license>
1823
<name>MIT license</name>
@@ -27,22 +32,18 @@
2732
</developer>
2833
</developers>
2934

30-
<build>
31-
<plugins>
32-
<plugin>
33-
<groupId>org.jenkins-ci.tools</groupId>
34-
<artifactId>maven-hpi-plugin</artifactId>
35-
<version>1.95</version>
36-
</plugin>
35+
<build>
36+
<plugins>
3737
<plugin>
38-
<artifactId>maven-javadoc-plugin</artifactId>
39-
<version>2.10.3</version>
38+
<groupId>org.jenkins-ci.tools</groupId>
39+
<artifactId>maven-hpi-plugin</artifactId>
40+
<!-- https://wiki.jenkins-ci.org/display/JENKINS/Marking+a+new+plugin+version+as+incompatible+with+older+versions -->
4041
<configuration>
41-
<failOnError>false</failOnError>
42+
<compatibleSinceVersion>3.0.0-SNAPSHOT</compatibleSinceVersion>
4243
</configuration>
43-
</plugin>
44-
</plugins>
45-
</build>
44+
</plugin>
45+
</plugins>
46+
</build>
4647

4748
<scm>
4849
<connection>scm:git:git://github.com/jenkinsci/parameterized-remote-trigger-tlugin.git</connection>
@@ -69,12 +70,30 @@
6970
<dependency>
7071
<groupId>org.jenkins-ci.plugins</groupId>
7172
<artifactId>credentials</artifactId>
72-
<version>1.9.4</version>
73+
<version>2.1.16</version>
7374
</dependency>
7475
<dependency>
7576
<groupId>org.jenkins-ci.plugins</groupId>
7677
<artifactId>token-macro</artifactId>
77-
<version>1.9</version>
78+
<version>2.3</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.jenkins-ci.plugins</groupId>
82+
<artifactId>script-security</artifactId>
83+
<version>1.34</version>
84+
<optional>true</optional>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
88+
<artifactId>workflow-step-api</artifactId>
89+
<version>2.13</version>
90+
<optional>true</optional>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.mockito</groupId>
94+
<artifactId>mockito-core</artifactId>
95+
<version>2.18.3</version>
96+
<scope>test</scope>
7897
</dependency>
7998
</dependencies>
8099

screenshots/1-system-settings.png

-28.3 KB
Loading
-6.69 KB
Loading
-10.4 KB
Loading
47.7 KB
Loading

0 commit comments

Comments
 (0)