Last active
November 5, 2020 09:20
-
-
Save binakot/83afd0aa77ea4f8723bf99e6023b42e4 to your computer and use it in GitHub Desktop.
Jenkins Pipeline Styles: Scripted VS Declarative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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