Skip to content

Instantly share code, notes, and snippets.

@binakot
Last active November 5, 2020 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binakot/83afd0aa77ea4f8723bf99e6023b42e4 to your computer and use it in GitHub Desktop.
Save binakot/83afd0aa77ea4f8723bf99e6023b42e4 to your computer and use it in GitHub Desktop.
Jenkins Pipeline Styles: Scripted VS Declarative
pipeline {
agent any
environment {
registry = 'https://my.registry.com'
registryCredential = 'docker-registry-login'
appName = 'application-name'
appVersion = '1.0.0-RELEASE'
dockerImage = ''
}
stages {
stage('checkout') {
steps {
checkout scm
}
}
stage('prepare') {
steps {
sh 'node --version'
sh 'npm --version'
sh 'ls -la'
}
}
stage('image build') {
steps {
script {
dockerImage = docker.build('$appName:$appVersion')
}
}
}
stage('image publish') {
steps {
script {
docker.withRegistry(registry, registryCredential) {
dockerImage.push()
}
}
}
}
}
post {
success {
sh 'echo success'
}
failure {
sh 'echo failure'
}
}
}
#!/usr/bin/env groovy
def version = '1.0.0-RELEASE'
node {
stage('checkout') {
checkout scm
}
stage('prepare') {
sh "node --version"
sh "npm --version"
sh "ls -la"
}
def dockerImage
stage('build image') {
dockerImage = docker.build('application-name')
}
stage('publish image') {
docker.withRegistry('https://my.registry.com', 'docker-registry-login') {
dockerImage.push version
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment