Created
November 10, 2019 09:15
-
-
Save ohmrefresh/d22529f44f15e3482b1740070456cc6d to your computer and use it in GitHub Desktop.
[Jenkins][Pipeline][Step1] How to implement Jenkins pipeline with Jenkinsfiles
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/groovy | |
import java.text.SimpleDateFormat | |
import java.util.* | |
import java.text.* | |
import groovy.json.JsonSlurper | |
import java.util.Date | |
def GIT_SOURCE_URL ='https://github.com/ohmrefresh/demo-jenkins-pipeline.git' | |
def API_ENDPOINT = 'https://www.ohmrefresh.club' | |
def DATE_FORMAT = new SimpleDateFormat("yyyyMMdd") | |
def SFTP_CONFIG_NAME = "demo-sftp" | |
properties([ | |
disableConcurrentBuilds(), | |
parameters([ | |
GIT_SOURCE_URL | |
string( | |
name: 'INPUT_DATE', | |
defaultValue: 'today', | |
description: 'YYYYMMDD'), | |
]), | |
[ | |
$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5'] | |
] | |
]) | |
pipeline { | |
agent any | |
environment { | |
directory = pwd() | |
} | |
triggers { | |
cron('0 7 * * *') | |
} | |
stages { | |
stage('Validate Parameter') { | |
} | |
stage('Clone Repo') { | |
} | |
stage('Excute SSH Over SSH') { | |
} | |
stage('Call Some API [with httpRequest plugin]') { | |
} | |
} | |
post { | |
always { | |
echo 'This will always run' | |
} | |
aborted { | |
echo 'Aborted' | |
} | |
success { | |
echo 'This will run only if successful' | |
} | |
failure { | |
echo 'This will run only if failed' | |
} | |
unstable { | |
echo 'This will run only if the run was marked as unstable' | |
} | |
changed { | |
echo 'This will run only if the state of the Pipeline has changed' | |
echo 'For example, if the Pipeline was previously failing but is now successful' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment