From 6a5572a5f7dff78bc41001507406163745697d62 Mon Sep 17 00:00:00 2001 From: Nana Janashia Date: Sun, 8 Nov 2020 15:58:31 +0100 Subject: [PATCH] call library functions in jenkinsfile --- Jenkinsfile | 17 ++++++++--------- script.groovy | 18 ++---------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8b55f4c..cd0cc7b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,10 @@ +#!/usr/bin/env groovy + +@Library('jenkins-shared-library') def gv pipeline { - agent any + agent none tools { maven 'Maven' } @@ -15,16 +18,12 @@ pipeline { } stage("build jar") { steps { - script { - gv.buildJar() - } + buildJar() } } stage("build image") { steps { - script { - gv.buildImage() - } + buildImage() } } stage("deploy") { @@ -34,5 +33,5 @@ pipeline { } } } - } -} \ No newline at end of file + } +} diff --git a/script.groovy b/script.groovy index 79ddb88..9cbe142 100644 --- a/script.groovy +++ b/script.groovy @@ -1,19 +1,5 @@ -def buildJar() { - echo "building the application..." - sh 'mvn package' -} - -def buildImage() { - echo "building the docker image..." - withCredentials([usernamePassword(credentialsId: 'docker-hub-repo', passwordVariable: 'PASS', usernameVariable: 'USER')]) { - sh 'docker build -t nanajanashia/demo-app:jma-2.0 .' - sh "echo $PASS | docker login -u $USER --password-stdin" - sh 'docker push nanajanashia/demo-app:jma-2.0' - } -} - def deployApp() { echo 'deploying the application...' -} +} -return this \ No newline at end of file +return this