Skip to content

Commit 3a280cb

Browse files
author
Antonio Mansilla
authored
Merge pull request #22 from trik/master
Add step definition for pipeline plugin
2 parents 22a6c06 + 9238452 commit 3a280cb

File tree

9 files changed

+706
-286
lines changed

9 files changed

+706
-286
lines changed

README.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Third, you need to add the Bitbucket OAuth Consumer credentials. You have two wa
7575
4. Click **Add** button.
7676
7. Select the desired credentials.
7777

78-
### Configure Jenkins to notify Bitbucket
78+
### Configure Jenkins to notify Bitbucket from a standard build
7979

8080
Once you have configured the credentials, configure jenkins to notify Bitbucket.
8181

@@ -84,6 +84,74 @@ Once you have configured the credentials, configure jenkins to notify Bitbucket.
8484
3. Select **Bitbucket notify build status**.
8585
4. Choose whether you want to notify the build status on Jenkins to Bitbucket.
8686

87+
### Pipeline step to notify Bitbucket
88+
89+
Once you have configured the credential, you can notify BitBucket from your Pipeline script through the `bitbucketStatusNotify` step.
90+
91+
#### Usage
92+
93+
The `bitbucketStatusNotify` step notifies the status of a build identified by a build key and build name to BitBucket.
94+
If `buildKey` and `buildName` parameters are not provided, a standard name will be assigned to the build (NameOfYourJob #numberOfBuild - eg. MyProject #32).
95+
When a `FAILED` status is sent to BitBucket, `bitbucketStatusNotify` throws an exception terminating your Pipeline.
96+
97+
```groovy
98+
...
99+
stage 'Build'
100+
bitbucketStatusNotify(
101+
buildState: 'INPROGRESS',
102+
buildKey: 'build',
103+
buildName: 'Build'
104+
)
105+
try {
106+
myBuildFunction()
107+
bitbucketStatusNotify(
108+
buildState: 'SUCCESSFUL',
109+
buildKey: 'build',
110+
buildName: 'Build'
111+
)
112+
} catch(Exception e) {
113+
bitbucketStatusNotify(
114+
buildState: 'FAILED',
115+
buildKey: 'build',
116+
buildName: 'Build',
117+
buildDescription: 'Something went wrong with build!'
118+
)
119+
}
120+
stage 'Test'
121+
bitbucketStatusNotify(
122+
buildState: 'INPROGRESS',
123+
buildKey: 'test',
124+
buildName: 'Test'
125+
)
126+
try {
127+
myTestFunction()
128+
bitbucketStatusNotify(
129+
buildState: 'SUCCESSFUL',
130+
buildKey: 'test',
131+
buildName: 'Test'
132+
)
133+
} catch(Exception e) {
134+
bitbucketStatusNotify(
135+
buildState: 'FAILED',
136+
buildKey: 'test',
137+
buildName: 'Test',
138+
buildDescription: 'Something went wrong with tests!'
139+
)
140+
}
141+
...
142+
```
143+
144+
#### API Summary
145+
146+
Parameter:
147+
148+
| Name | Type | Optional | Description |
149+
| --- | --- | --- | --- |
150+
| `buildState` | `"INPROGRESS"|"SUCCESSFUL"|"FAILED"` | no | The status of the current build phase
151+
| `buildKey` | String | yes | The unique key identifying the current build phase
152+
| `buildName` | String | yes | The build phase's name shown on BitBucket
153+
| `buildDescription` | String | yes | The build phase's description shown on BitBucket
154+
87155
## Contributions
88156

89157
Contributions are welcome! For feature requests and bug reports please read the following Wiki page for guidelines on [how to submit an issue][how-to-submit-issue].

pom.xml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>org.jenkins-ci.plugins</groupId>
77
<artifactId>plugin</artifactId>
88
<!-- Baseline Jenkins version you use to build and test the plugin. Users must have this version or newer to run. -->
9-
<version>1.580.1</version>
9+
<version>1.609.1</version>
1010
<relativePath />
1111
</parent>
1212

@@ -20,6 +20,7 @@
2020
<maven-hpi-plugin.version>1.112</maven-hpi-plugin.version>
2121
<maven-deploy-plugin.version>2.6</maven-deploy-plugin.version>
2222
<wagon-http.version>2.10</wagon-http.version>
23+
<workflow.version>1.11</workflow.version>
2324
</properties>
2425

2526
<name>Bitbucket Build Status Notifier Plugin</name>
@@ -84,6 +85,41 @@
8485
<artifactId>mercurial</artifactId>
8586
<version>1.54</version>
8687
</dependency>
88+
<dependency>
89+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
90+
<artifactId>workflow-step-api</artifactId>
91+
<version>${workflow.version}</version>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
95+
<artifactId>workflow-cps</artifactId>
96+
<version>${workflow.version}</version>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
100+
<artifactId>workflow-job</artifactId>
101+
<version>${workflow.version}</version>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
105+
<artifactId>workflow-aggregator</artifactId>
106+
<version>${workflow.version}</version>
107+
<scope>test</scope>
108+
</dependency>
109+
<dependency>
110+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
111+
<artifactId>workflow-aggregator</artifactId>
112+
<classifier>tests</classifier>
113+
<version>${workflow.version}</version>
114+
<scope>test</scope>
115+
</dependency>
116+
<dependency>
117+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
118+
<artifactId>workflow-step-api</artifactId>
119+
<classifier>tests</classifier>
120+
<version>${workflow.version}</version>
121+
<scope>test</scope>
122+
</dependency>
87123
<dependency>
88124
<groupId>com.google.code.gson</groupId>
89125
<artifactId>gson</artifactId>
@@ -158,4 +194,4 @@
158194
<url>https://repo.jenkins-ci.org/releases</url>
159195
</repository>
160196
</distributionManagement>
161-
</project>
197+
</project>

0 commit comments

Comments
 (0)