开源软件名称(OpenSource Name):fabric8io/jenkins-pipeline-library开源软件地址(OpenSource Url):https://github.com/fabric8io/jenkins-pipeline-library开源编程语言(OpenSource Language):Groovy 100.0%开源软件介绍(OpenSource Introduction):WARNING THIS REPOSITORY IS NOW DEPRECATED!NOTE please use one of these repositories instead:
Table of Contents
Fabric8 Jenkins Pipeline LibraryThis git repository contains a library of reusable Jenkins Pipeline scripts that can be used on a project. The idea is to try promote sharing of scripts across projects where it makes sense. You can then either
RequirementsThese flows make use of the Fabric8 DevOps Pipeline Steps and kubernetes-pipeline-plugin which help when working with Fabric8 DevOps in particular for clean integration with the Hubot chat bot and human approval of staging, promotion and releasing. How it worksWith the Jenkins global library we can take advantage from a shared library of reusable scripts. When the fabric8 Jenkins app is run, we use a kubernetes post start script to populate the Jenkins internal global library with scripts from this repo. We are then able to easily call the groovy functions from within our Jenkinsfiles. NOTE Hopefully we will switch to using Kubernetes initContainers when they're available to help with this. These scripts are baked into the fabric8 jenkins docker image during the fabric8 release however you can override this repo by updating the parameters when running the Jenkins app from the fabric8 console. Functions from the Jenkins global libraryApprove
example.. approve{
version = '0.0.1'
console = 'http://fabric8.kubernetes.fabric8.io'
environment = 'staging'
} Deploy Project
deployProject{
stagedProject = 'my-project'
resourceLocation = 'target/classes/kubernetes.json'
environment = 'staging'
} Drop Projectin the case of an aborted approval
dropProject{
stagedProject = project
pullRequestId = '1234'
} Get Kubernetes JSON
node {
def rc = getKubernetesJson {
port = 8080
label = 'node'
icon = 'https://cdn.rawgit.com/fabric8io/fabric8/dc05040/website/src/images/logos/nodejs.svg'
version = '0.0.1'
}
kubernetesApply(file: rc, environment: 'my-cool-app-staging', registry: 'myexternalregistry.io:5000')
} Get New Version
def newVersion = getNewVersion{} Maven Canary Release
mavenCanaryRelease{
version = canaryVersion
} Maven Integration Test
mavenIntegrationTest{
environment = 'Testing'
failIfNoTests = 'false'
itestPattern = '*KT'
} Merge and Wait for Pull Request
mergeAndWaitForPullRequest{
project = 'fabric8/fabric8'
pullRequestId = prId
} Perform Canary Release
stage 'Canary release'
echo 'NOTE: running pipelines for the first time will take longer as build and base docker images are pulled onto the node'
if (!fileExists ('Dockerfile')) {
writeFile file: 'Dockerfile', text: 'FROM django:onbuild'
}
def newVersion = performCanaryRelease {} REST Get URL
def apiUrl = new URL("https://api.github.com/repos/${config.name}/pulls/${id}")
JsonSlurper rs = restGetURL{
authString = githubToken
url = apiUrl
} Update Maven Property VersionDuring a release involving multiple java projects we often need to update downstream maven poms with new versions of a dependency. In a release pipeline we want to automate this, set up a pull request and let CI run to make sure there's no conflicts.
If CI fails and updates are required as a result of the dependency upgrade then
Automating this has saved us a lot of time during the release pipeline def properties = []
properties << ['<fabric8.version>','io/fabric8/kubernetes-api']
properties << ['<docker.maven.plugin.version>','io/fabric8/docker-maven-plugin']
updatePropertyVersion{
updates = properties
repository = source // if null defaults to http://central.maven.org/maven2/
project = 'fabric8io/ipaas-quickstarts'
} Wait Until Artifact Synced With Maven CentralWhen working with open source java projects we need to stage artifacts with OSS Sonartype in order to promote them into maven central. This can take 10-30 mins depending on the size of the artifacts being synced. A useful thing is to be notified in chat when artifacts are available in maven central as blocking the pipeine until we're sure the promote has worked.
waitUntilArtifactSyncedWithCentral {
repo = 'http://central.maven.org/maven2/'
groupId = 'io.fabric8.archetypes'
artifactId = 'archetypes-catalog'
version = '0.0.1'
ext = 'jar'
} Wait Until Pull Request MergedDuring a CD pipeline we often need to wait for external events to complete before continuing. One of the most common events we have on the fabric8 project is waiting for CI jobs or manually review and approval of github pull requests. We don't want to fail a pipeline, rather just wait patiently for the pull requests to merge so we can continue.
If CI fails and updates are required as a result of the dependency upgrade then
waitUntilPullRequestMerged{
name = 'fabric8io/fabric8'
prId = '1234'
} fabric8 releaseThese functions are focused specifically on the fabric8 release itself however could be used as examples or extended in users own setup. The core fabric8 release consists of multiple Java projects that generate Java artifacts, docker images and kubernetes resources. These projects are built and staged together, automatically deployed into a test environment and after approval promoted together ready for the community to use. When a project is staged an array is returned and passed around functions further down the pipeline. The structure of this stagedProject array is in the form
def stagedProject = stageProject{
project = 'fabric8io/ipaas-quickstarts'
useGitTagForNextVersion = true
} One other important note is on the fabric8 project we don't use the maven release plugin or update to next SNAPSHOT versions as it causes unwanted noise and commits to our many github repos. Instead we use a fixed development Now that we don't store the next release version in the poms we need to figure it out during the release. Rather than store the version number in the repo which involves a commit and not too CD friendly (i.e. would trigger another release just for the version update) we use the Promote Artifacts
String pullRequestId = promoteArtifacts {
projectStagingDetails = config.stagedProject
project = 'fabric8io/fabric8'
useGitTagForNextVersion = true
helmPush = false
} Release Project
releaseProject{
stagedProject = project
useGitTagForNextVersion = true
helmPush = false
groupId = 'io.fabric8.archetypes'
githubOrganisation = 'fabric8io'
artifactIdToWatchInCentral = 'archetypes-catalog'
artifactExtensionToWatchInCentral = 'jar'
} Stage Extra Images
stageExtraImages {
images = ['gogs','jenkins','taiga']
tag = releaseVersion
} Stage Project
def stagedProject = stageProject{
project = 'fabric8io/ipaas-quickstarts'
useGitTagForNextVersion = true
} Tag Images
tagImages{
images = ['gogs','jenkins','taiga']
tag = releaseVersion
} Git Tag
gitTag{
releaseVersion = '0.0.1'
} Deploy Remote OpenShiftDeploys the staged fabric8 release to a remote OpenShift cluster NOTE in order for images to be found by the the remote OpenShift instance it must be able to pull images from the staging docker registry. Noting private networks and insecure-registry flags. node{
deployRemoteOpenShift{
url = openshiftUrl
domain = 'staging'
stagingDockerRegistry = openshiftStagingDockerRegistryUrl
}
} Deploy Remote KubernetesDeploys the staged fabric8 release to a remote Kubernetes cluster NOTE in order for images to be found by the the remote OpenShift instance it must be able to pull images from the staging docker registry. Noting private networks and insecure-registry flags. node{
deployRemoteKubernetes{
url = kubernetesUrl
defaultNamespace = 'default'
stagingDockerRegistry = kubernetesStagingDockerRegistryUrl
}
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论