Added Readme and Gitea wrapper
This commit is contained in:
parent
01cbadbaef
commit
203a1fec91
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
||||
# External Jenkins pipeline helpers
|
||||
|
||||
## Usage:
|
||||
Inside Jenkins pipeline script run two following commands:
|
||||
```groovy
|
||||
// This shell command will download groovy helpers file
|
||||
sh "curl -L http://[git-url]/[organization]/[repo-name]/raw/branch/master/helpers.groovy -o helpers.groovy"
|
||||
|
||||
// This will load script to the pipeline
|
||||
load "helpers.groovy"
|
||||
```
|
||||
> This can be used in scripting pipeline syntax only!
|
||||
|
||||
After all you will have in your pipeline all functions that `helpers.groovy` provides:
|
||||
- stageWithChecks
|
||||
- setSuccessCheck
|
||||
- withGiteaCreds
|
@ -1,10 +1,50 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
*
|
||||
* Helper function that emits `Success` status.
|
||||
*
|
||||
*/
|
||||
def setSuccessCheck(String name, String title) {
|
||||
publishChecks name: name, title: title, summary: '— Successful', conclusion: "SUCCESS"
|
||||
publishChecks(
|
||||
name: name,
|
||||
title: title,
|
||||
summary: '— Successful',
|
||||
conclusion: "SUCCESS"
|
||||
)
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Replacement for `stage` function for default pipeline.
|
||||
*
|
||||
* Has the same arguments but does side-effects to the stage:
|
||||
* 1. Runs stage with Gitea checks. It will automatically set check status
|
||||
* as running and failed if stage is failed.
|
||||
*
|
||||
* 2. If stage was successful it will emit `Success` state as a check.
|
||||
*
|
||||
*/
|
||||
def stageWithChecks(String name, Closure body) {
|
||||
stage(name) {
|
||||
body()
|
||||
setSuccessCheck(name, name)
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Wrapper function for `withCredentials` and `gitUsernamePassword` tool.
|
||||
*
|
||||
* By passing `credentialsId` and `gitToolName` it will execute next provided
|
||||
* closure with already activated credentials on git commands.
|
||||
*
|
||||
*/
|
||||
def withGiteaCreds(String credentialsId, String gitToolName, Closure body) {
|
||||
withCredentials([
|
||||
gitUsernamePassword(
|
||||
credentialsId: credentialsId,
|
||||
gitToolName: gitToolName
|
||||
)
|
||||
]) {
|
||||
body()
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
Loading…
x
Reference in New Issue
Block a user