在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):fabric8io/fabric8-pipeline-library开源软件地址(OpenSource Url):https://github.com/fabric8io/fabric8-pipeline-library开源编程语言(OpenSource Language):Groovy 100.0%开源软件介绍(OpenSource Introduction):Table of Contents
Fabric8 Pipeline LibraryThis git repository contains a library of reusable Jenkins Pipeline steps and functions that can be used in your The idea is to try promote sharing of scripts across projects where it makes sense. How to use this libraryThis library is intended to be used with fabric8's Jenkins image that is deployed as part of the fabric8 platform. To use the functions in this library just add the following to the top of your @Library('github.com/fabric8io/fabric8-pipeline-library@master') _ That will use the master branch of this library. You can if you wish pick a specific tag or commit SHA of this repository too. Making changesFeel free to reuse a version of this library as is. However if you want to make changes, please Then just refer to your fork in the If you do make local changes we'd love a RequirementsThese flows make use of the Fabric8 DevOps Pipeline Steps and kubernetes-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. 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 Deployment Resources
node {
def resources = getDeploymentResources {
port = 8080
label = 'node'
icon = 'https://cdn.rawgit.com/fabric8io/fabric8/dc05040/website/src/images/logos/nodejs.svg'
version = '0.0.1'
}
kubernetesApply(file: resources, environment: 'my-cool-app-staging', registry: 'myexternalregistry.io:5000')
} Get Kubernetes JSONWARNING this function is deprecated. Please change to use getDeploymentResources{}
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{
goal = "deploy" # executes `mvn deploy` instead of `mvn install`
}
mavenCanaryRelease{
profile = "osio" # executes `mvn install -P osio`
}
mavenCanaryRelease{
cmd = "mvn clean -B -e -U deploy -Dmaven.test.skip=true -P profile"
} NOTE: if
mavenCanaryRelease{
autoUpdateFabric8Plugin = false // disables patching pom.xml
} Maven Integration Test
mavenIntegrationTest {
environment = 'Testing'
failIfNoTests = 'false'
itestPattern = '*KT'
}
mavenIntegrationTest {
cmd = 'mvn -P openshift-it org.apache.maven.plugins:maven-failsafe-plugin:verify'
} Note: All other flags are ignored if 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 Sonatype 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 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 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
}
} Add Annotation To BuildAdd an annotation to the matching openshift build @Library('github.com/fabric8io/fabric8-pipeline-library@master')
def dummy
node {
def utils = new io.fabric8.Utils()
utils.addAnnotationToBuild('fabric8.io/foo', 'bar')
} Understanding how it worksMost of the functions provided by this library are meant to run inside a Kubernetes or Openshift pod. Those pods are managed by the kubernetes plugin. This library abstracts the pipeline capabilities of kubernetes plugin so that it makes it easier to use. So for example when you need to use a pod with maven capabilities instead of defining something like:
You can just use the mavenTemplate provided by this library:
or for ease of use you can directly reference the mavenNode:
Template vs NodeA template defines how the jenkins slave pod will look like, but the pod is not created until a node is requested. When a node is requested the matching template will be selected and pod from the template will be created. The library provides shortcut function both to nodes and templates. In most cases you will just need to use the node. The only exception is when you need to mix and match (see mixing and matching). The provided node / template pairs are the following:
Maven NodeProvides maven capabilities by adding a container with the maven image. The container mounts the following volumes:
The maven node and template support limited customization through the following properties:
Example:
Docker NodeProvides docker capabilities by adding a container with the docker binary. The container mounts the following volumes:
Host path mounts are not allowed everywhere, so use with caution. Also note that the mount will be mounted to all containers in the pod. This means that if we add a maven container to the pod, it will have docker capabilities. The docker node and template support limited customization through the following properties:
Example:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论