You don't need to create complex Jenkinsfile for Pipeline. Instead, configure the pipline using a yaml and Jenkinsfile that contain single method call.
Create two file in your project root.
# Define your dynamic pipeline stage
# - Details will be configured as same name
stage:
- build
- deploy
# configuration for 'build' stage.
# - keys are will be used as container name (maven and docker)
# - values are will be executed as shell command
build:
- maven: mvn --version
- docker: docker version
# configuration for 'build' stage. (no effect now)
deploy:
- k8s: k8s/*.yaml
# configuration for creating slave at k8s
agent:
containers:
- name: maven
image: maven:3.3.9-jdk-8-alpine
ttyEnabled: true
command: cat
- name: docker
image: docker
ttyEnabled: true
command: cat
volumes:
- hostPathVolume:
hostPath: '/var/run/docker.sock'
mountPath: '/var/run/docker.sock'
// Just add a below simple Jenkinsfile.
// This code will execute a pipeline that is prepared as pipeline shared library.
@Library('retort') _
heat()
To use prepared pipeline, select definition type as Pipeline script from SCM
.
Write down your repository info.
And also click add
button for creating credentials, if you use private repository.
The library load your configration(.yaml) at *prepared
stage.
And then detect two stages using those config.
Stages are run at k8s and master. In k8s, run and print version of tools by configured shell script.