All Projects → liejuntao001 → jenkins-k8sagent-lib

liejuntao001 / jenkins-k8sagent-lib

Licence: MIT license
Jenkins Shared Library to get dynamic agent from Kubernetes cloud

Programming Languages

groovy
2714 projects

Projects that are alternatives of or similar to jenkins-k8sagent-lib

jenkins-pipeline-global-library-chefci
Jenkins Pipeline's "Workflow Global Libs" for Chef CI
Stars: ✭ 60 (+71.43%)
Mutual labels:  jenkins, jenkins-pipeline, jenkins-shared-library
ods-jenkins-shared-library
Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Stars: ✭ 51 (+45.71%)
Mutual labels:  jenkins, jenkins-pipeline
eryajf.github.io
📝 大千世界,何其茫茫。谨此笔记,记录过往。凭君阅览,小站洛荒。如能收益,莫大奢望
Stars: ✭ 159 (+354.29%)
Mutual labels:  jenkins, jenkins-pipeline
pipeline-maven-plugin
Pipeline Maven Plugin
Stars: ✭ 50 (+42.86%)
Mutual labels:  jenkins, jenkins-pipeline
learn-ansible-and-jenkins-in-30-days
Ansible + Jenkins in 30 days tutorial.
Stars: ✭ 35 (+0%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-pipeline-shared-library-template
Project template for developing shared Jenkins pipeline libraries.
Stars: ✭ 46 (+31.43%)
Mutual labels:  jenkins, jenkins-pipeline
pipeline-library
Shared libraries for Jenkinsfiles with unit tests
Stars: ✭ 22 (-37.14%)
Mutual labels:  jenkins, jenkins-pipeline
soccer-stats
Soccer Stats is an example application to be used as a proof of concept for a presentation at Ansible Meetup in São Paulo
Stars: ✭ 83 (+137.14%)
Mutual labels:  jenkins, jenkins-pipeline
jenkinsfile cookbook pipeline
Example Jenkinsfile and Explaination for Chef Cookbook Development
Stars: ✭ 36 (+2.86%)
Mutual labels:  jenkins, jenkins-pipeline
pipeline-lib
Global shared library for Glia pipeline jobs
Stars: ✭ 68 (+94.29%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-shared-library-example
Example for a Jenkins shared library with unit tests
Stars: ✭ 35 (+0%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-pipeline
Jenkins Pipeline Shared Library
Stars: ✭ 16 (-54.29%)
Mutual labels:  jenkins, jenkins-pipeline
pipeline-as-yaml-plugin
Jenkins Pipeline As Yaml Plugin
Stars: ✭ 111 (+217.14%)
Mutual labels:  jenkins, jenkins-pipeline
plot-plugin
Jenkins plot plugin
Stars: ✭ 54 (+54.29%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins pipeline
A lean Continuous Deployment, Testing and Integration Pipeline using CoreOS/Docker/Jenkins
Stars: ✭ 44 (+25.71%)
Mutual labels:  jenkins, jenkins-pipeline
movie-db-java-on-azure
Sample movie database app built using Java on Azure
Stars: ✭ 28 (-20%)
Mutual labels:  jenkins, jenkins-pipeline
jenny
Command line Jenkinsfile runner written in groovy. Does not need a Jenkins installation to run the Jenkinsfile.
Stars: ✭ 90 (+157.14%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-watch
Display jenkins/hudson build status on the emacs modeline.
Stars: ✭ 28 (-20%)
Mutual labels:  jenkins
rabbitChat
A Chat-Server/Chat-System based on AMQP protocol(RabbitMQ) + AMQP Python Client(PIKA) + Websockets(SockJS) + Async Python Server(Tornado)
Stars: ✭ 53 (+51.43%)
Mutual labels:  jenkins
vagrant-jenkins
Vagrant box running Ubuntu with an installed Jenkins instance
Stars: ✭ 39 (+11.43%)
Mutual labels:  jenkins

Jenkins Shared Library to get dynamic agent from Kubernetes cloud

This is a Jenkins Shared Library to get a dynamic agent from Kubernetes cloud.

Define the required agent in format "a+b+c", for example, "small+pg+privileged" to get an agent of "small size, additional postgres container and jnlp container running in privileged mode".
It's flexible to add templates in folder resources/podtemplates. The yaml files will be merged together and passed to Kubernetes Plugin to launched the desired pod.

Below lines will get an agent with 2 containers in the pod, a JNLP container of "mini" size plus a "postgres" container.

pipeline {
  agent {
    kubernetes(k8sagent(name: 'mini+pg'))
  }
  stages {
    stage('demo') {
      steps {
        echo "this is a demo"
        script {
          container('pg') {
            sh 'su - postgres -c \'psql --version\''
          }
        }
      }
    }
  }
}

A more sophisticated example is here, where you could decide the agent type with more complex logic.

Preconditionl

  • Running Kubernetes cluster
  • Jenkins server with connection to the cluster
  • Kubernetes Plugin installed on the Jenkins

The Jenkins server could be stand-alone or be running inside the Kubernetes cluster.

Usage

Recommended Method 1 - Import into Jenkins

Import the library following the instruction import

Use it in pipeline

@Library("k8sagent") _

Method 2 - Load dynamically

@Library("github.com/liejuntao001/jenkins-k8sagent-lib") _

However due to Jenkins security control, multiple methods need get approved.

Build and test

The library is a gradle project with tests.

.
├── build.gradle
├── src
│   └── com
├── test
│   ├── com
│   └── groovy
├── testjobs
│   ├── k8sagent_Jenkinsfile.groovy
│   └── simple_Jenkinsfile.groovy
└── vars
    └── k8sagent.groovy

Local build and test

./gradlew clean test

> Task :test
K8sAgentTest: testSdk25: SUCCESS
K8sAgentTest: testSmall: SUCCESS
K8sAgentTest: testBase: SUCCESS
K8sAgentTest: testFast: SUCCESS
K8sAgentTest: testPg: SUCCESS
K8sAgentTest: testPrivileged: SUCCESS
Tests: 6, Failures: 0, Errors: 0, Skipped: 0


BUILD SUCCESSFUL in 2s
6 actionable tasks: 5 executed, 1 up-to-date

Run the demo in a real Jenkins Job .

demojob

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].