Jenkins shared library

This commit is contained in:
Layla 2019-12-20 12:44:07 -05:00
parent 9876ad734f
commit 9e2e52e4e6
2 changed files with 81 additions and 4 deletions

View File

@ -21,14 +21,14 @@ Below is an example configuration of a `.bumpversion.cfg` file using commits:
```ini
[bumpversion]
current_version = develop
current_version = 0.0.0
commit = False
tag = True
tag_name = {new_version}
message = Bump version: {current_version} -> {new_version}
[bumpversion:file:VERSION]
search = version=develop
search = version=0.0.0
replace = version={new_version}
[semver]
@ -42,14 +42,14 @@ patch_branches = hotfix, bugfix
```ini
[bumpversion]
current_version = 1.5.2
current_version = 0.0.0
commit = False
tag = True
tag_name = v{new_version}
message = Bump version: {current_version} -> {new_version}
```
The `current_version` represents the default version of the application contained in the repository. This must match what is in the VERSION file (example shown below). The `commit` and `tag` options determine whether to create a new Git commit and a new Git tag, respectively. The `tag_name` represents what the name of the Git tag will be, and by default is set to `{new_version}`, which will be substitued with the new version during runtime. This can be changed as desired - for example, `v{new_version}` could resolve to `v1.15.5`. The `message` option is what the message used if there is a git commit.
The `current_version` exists to tell bumpversion what the current version is. To have auto-semver manage this value, set it to `0.0.0` This must match what is in the VERSION file (example shown below). The `commit` and `tag` options determine whether to create a new Git commit and a new Git tag, respectively. The `tag_name` represents what the name of the Git tag will be, and by default is set to `{new_version}`, which will be substitued with the new version during runtime. This can be changed as desired - for example, `v{new_version}` could resolve to `v1.15.5`. The `message` option is what the message used if there is a git commit.
### File updates
@ -132,3 +132,36 @@ Replaces `/` with `.` in branch names. For example, `feature/test` becomes `feat
### Commitless Versioning
Because auto-semver keeps track of the version by looking at the latest git tag, instead of commiting versioned values to the repository, files can be updated upon release.
### Jenkins Shared Library
This repository is also home to a Jenkins shared library to assit in running auto-semver.
```groovy
library('auto-semver')
pipeline
{
options { timestamps() }
agent any
environment {
GIT_KEY = 'githubKey' // Git credentials
}
stages{
stage('Version') {
steps {
runAutoSemver()
}
}
stage('Push Version and Tag') {
steps {
gitPushTags(env.GIT_KEY)
}
}
}
}
```
#### runAutoSemver( String _dockerImage_ )
**dockerImage:** The Docker image and tag to run auto-semver with. By default, it pulls `rbnops/auto-semver:latest`.

44
vars/runAutoSemver.groovy Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env groovy
/**
* Runs "semver -n". Upon successful return, pushes changes from remote repo
* to ${env.GIT_BRANCH}.
*
* @param dockerImage (Optional) The docker image with semver to run in environment
*
*/
// Run Auto Semver
def call(dockerImage = "auto-semver:latest") {
def docker_image = docker.image(dockerImage)
docker_image.pull()
docker_image.inside{
def RETURN_STATUS
def regex = '^\\s*current_version\\s*=\\s*\\K[^\\s]+'
RETURN_STATUS = sh(script: "semver -n", returnStatus: true)
echo "Semver Return Status: ${RETURN_STATUS}"
env.SEMVER_STATUS = RETURN_STATUS
switch (RETURN_STATUS) {
case "0":
echo 'Versioned will push after build/test.'
break
case "128":
echo 'Unknown Semver Failure'
sh 'exit 1'
break
default:
echo 'No versioning required.'
break
}
env.SEMVER_NEW_VERSION = sh(script: "grep -Po '${regex}' .bumpversion.cfg", returnStdout: true).trim()
env.SEMVER_RESOLVED_VERSION = getVersion('-d')
env.VERSION = getVersion('-d')
}
}