Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sivaprasadreddy/jenkins-shared-library
jenkins-shared-library
https://github.com/sivaprasadreddy/jenkins-shared-library
gradle java jenkinsfile maven pipeline
Last synced: 23 days ago
JSON representation
jenkins-shared-library
- Host: GitHub
- URL: https://github.com/sivaprasadreddy/jenkins-shared-library
- Owner: sivaprasadreddy
- Created: 2018-12-14T05:51:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-04T01:22:53.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T11:30:02.358Z (7 months ago)
- Topics: gradle, java, jenkinsfile, maven, pipeline
- Language: Groovy
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 2
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jenkins-shared-library
## Usage
### Configure Global Shared Library
* Go to **Manage Jenkins -> Configure System**
* In **Global Pipeline Libraries** Section
* Library Name: jenkins-shared-library
* Default version: master
* Check "Allow default version to be overridden", "Include @Library changes in job recent changes"
* Retrieval method: "Modern SCM"
* Source Code Management: Git, Project Repository: "https://github.com/sivaprasadreddy/jenkins-shared-library.git"
### Scripted Pipeline**Jenkinsfile**
```groovy
#!groovy
@Library('jenkins-shared-library')
import com.sivalabs.JenkinsMavenLib
import com.sivalabs.JenkinsGradleLibdef dockerUsername = 'DOCKER_USERNAME'
def dockerImageName = 'IMAGE_NAME'def project = new JenkinsMavenLib(this, scm, env, params, currentBuild)
//def project = new JenkinsGradleLib(this, scm, env, params, currentBuild)node {
try {
stage("Checkout") {
project.checkout()
}
stage("Build") {
project.runTests()
}
stage("Publish Docker Image") {
project.buildSpringBootDockerImage(dockerUsername, dockerImageName)
def tags = []
if(env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'main') {
tags << "latest"
}
project.publishDockerImage(dockerUsername, dockerImageName, tags)
}
}
catch(err) {
echo "ERROR: ${err}"
currentBuild.result = currentBuild.result ?: "FAILURE"
}
}
```### Declarative Pipeline
**Jenkinsfile**
```groovy
#!groovy
@Library('jenkins-shared-library')
import com.sivalabs.JenkinsMavenLib
//import com.sivalabs.JenkinsGradleLibdef project = new JenkinsMavenLib(this, scm, env, params, currentBuild)
//def project = new JenkinsGradleLib(this, scm, env, params, currentBuild)pipeline {
agent anystages {
stage("Checkout") {
steps {
script {
project.checkout()
}
}
}
stage("Test") {
steps {
script {
project.runTests()
}
}
}
}
}
```### Dynamically loading library
**Jenkinsfile**
```groovy
#!groovyjsl = library(
identifier: 'jenkins-shared-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/sivaprasadreddy/jenkins-shared-library.git'
]
)
)def project = jsl.com.sivalabs JenkinsMavenLib.new(this, scm, env, params, currentBuild)
node {
try {
stage("Checkout") {
project.checkout()
}
stage("Build") {
project.runTests()
}
}
catch(err) {
echo "ERROR: ${err}"
currentBuild.result = currentBuild.result ?: "FAILURE"
}
}
```