-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b9a15f
commit cd60966
Showing
2 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
def projectName='eva-activepieces' | ||
def autoCancelled = false | ||
|
||
script { | ||
buildCause = currentBuild.getBuildCauses()[0].shortDescription | ||
echo buildCause | ||
} | ||
|
||
pipeline { | ||
agent { | ||
label "general" | ||
} | ||
parameters { | ||
choice(name: 'GIT_SOURCE', choices: [env.GIT_SOURCE], description: 'Branch, Tag, CommitId - you need to hardcode the src at the configuration at \'Branch Specifier\'. Please revert the hardcode back after.') | ||
choice(name: 'Env', choices: [env.Env], description: '') | ||
booleanParam(name: 'force_rebuild', defaultValue: false, description: 'this forces docker image rebuild with cache flush') | ||
} | ||
triggers { | ||
githubPush() | ||
} | ||
options { | ||
timestamps() | ||
disableConcurrentBuilds() | ||
disableResume() | ||
parallelsAlwaysFailFast() | ||
buildDiscarder(logRotator(daysToKeepStr: '30')) | ||
timeout(time: 45, unit: 'MINUTES') | ||
} | ||
stages { | ||
stage('Set environment variables'){ | ||
steps { | ||
script { | ||
env.TEST_COMPANY_ID="test" | ||
if (env.Env == 'dev') { | ||
env.PGHOST="devdb.eva.ai" | ||
env.JIRA_ENV_CODE="development" | ||
} | ||
if (env.Env == 'uat') { | ||
env.PGHOST="uatdb.eva.ai" | ||
env.JIRA_ENV_CODE="staging" | ||
} | ||
if (env.Env == 'prd') { | ||
env.PGHOST="prddb.eva.ai" | ||
env.JIRA_ENV_CODE="production" | ||
} | ||
} | ||
sh 'aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 835065412841.dkr.ecr.eu-west-1.amazonaws.com' | ||
} | ||
} | ||
stage('Clean') { | ||
steps { | ||
sh 'rm -f *.xml *.log' | ||
} | ||
} | ||
stage('Build and Publish NPM package...'){ | ||
steps { | ||
withCredentials([usernameColonPassword(credentialsId: 'EVA-ActivePieces', variable: 'EVA_NPMJS_CREDS')]) { | ||
sh ''' | ||
docker build . --build-arg CREDS=//registry.npmjs.org/:_authToken=$EVA_NPMJS_CREDS --build-arg APP_VERSION='1.0.0.'${BUILD_NUMBER} \ | ||
-t 835065412841.dkr.ecr.eu-west-1.amazonaws.com/''' + projectName + ''':${Env}-latest-`git rev-parse HEAD | cut -c1-7`-${BUILD_NUMBER} | ||
''' | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
success { | ||
slackSend (color: '#00FF00', message: "SUCCESS: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}] Build cause: '$buildCause' (${env.BUILD_URL})") | ||
cleanWs( | ||
deleteDirs: true, | ||
notFailBuild: true, | ||
patterns: [ | ||
[pattern: '.git/**', type: 'EXCLUDE'] | ||
] | ||
) | ||
} | ||
failure { | ||
slackSend (color: '#FF0000', message: "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}] Build cause: '$buildCause' @channel' (${env.BUILD_URL})") | ||
} | ||
always { | ||
sh """ | ||
docker logs ${BUILD_TAG} > ${BUILD_TAG}.log 2>&1 || true | ||
docker rmi 835065412841.dkr.ecr.eu-west-1.amazonaws.com/${projectName}:${env.Env}-latest-`git rev-parse HEAD | cut -c1-7`-${BUILD_NUMBER} || true | ||
if [ "${env.Env}" = "prd" ]; then | ||
docker rmi 835065412841.dkr.ecr.eu-west-1.amazonaws.com/${projectName}:${env.Env}-latest || true | ||
fi | ||
docker rmi \$(docker image ls --filter=dangling=true --filter=reference=835065412841.dkr.ecr.eu-west-1.amazonaws.com/${projectName} -q) || true | ||
""" | ||
archiveArtifacts artifacts: '*.log', allowEmptyArchive: true | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
def projectName='eva-activepieces' | ||
|
||
// Manages communication with github for reporting important status | ||
// events. Relies on Github integration plugin https://github.com/jenkinsci/github-plugin | ||
class GithubStatus { | ||
|
||
// Repository to send status e.g: '/username/repo' | ||
String ghprbGhRepository | ||
|
||
// Commit hash to send status e.g: `909b76f97e` | ||
String ghprbActualCommit | ||
|
||
// Build url send status e.g: `https://jenkins/build/123` | ||
String BUILD_URL | ||
|
||
// Set pending status for this pull request | ||
def setPending(script) { | ||
this.setBuildStatusStep(script, "In Progress", "PENDING") | ||
} | ||
|
||
// Set failed status for this pull request | ||
def setFailed(script) { | ||
this.setBuildStatusStep(script, "Complete", "FAILURE") | ||
} | ||
|
||
// Set success status for this pull request | ||
def setSuccess(script) { | ||
this.setBuildStatusStep(script, "Complete", "SUCCESS") | ||
} | ||
|
||
// Manually set PR status via GitHub integration plugin. Manual status updates are needed | ||
// Due to pipeline stage retries not propagating updates back to Github automatically | ||
// https://github.com/KostyaSha/github-integration-plugin/issues/102#issuecomment-299641073 | ||
def setBuildStatusStep(script, String message, String state) { | ||
def commitContextName = "Jenkins Build and Test" | ||
script.step([ | ||
$class: "GitHubCommitStatusSetter", | ||
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "https://github.com/${this.ghprbGhRepository}"], | ||
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: commitContextName], | ||
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]], | ||
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: this.ghprbActualCommit], | ||
statusBackrefSource: [$class: "ManuallyEnteredBackrefSource", backref: "${this.BUILD_URL}flowGraphTable/"], | ||
statusResultSource: [$class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ] | ||
]) | ||
} | ||
} | ||
def githubStatus = new GithubStatus( | ||
ghprbGhRepository: env.ghprbGhRepository, | ||
ghprbActualCommit: env.ghprbActualCommit, | ||
BUILD_URL: env.BUILD_URL | ||
) | ||
|
||
script { | ||
buildCause = currentBuild.getBuildCauses()[0].shortDescription | ||
echo buildCause | ||
} | ||
|
||
pipeline { | ||
agent { | ||
label "general" | ||
} | ||
options { | ||
timestamps() | ||
disableResume() | ||
parallelsAlwaysFailFast() | ||
buildDiscarder(logRotator(daysToKeepStr: '15')) | ||
timeout(time: 45, unit: 'MINUTES') | ||
} | ||
parameters { | ||
choice(name: 'Env', choices: ['dev'], description: '') | ||
booleanParam(name: 'force_rebuild', defaultValue: false, description: 'this forces docker image rebuild with cache flush') | ||
} | ||
stages { | ||
stage('Set PENDING GitHub status') { | ||
steps { | ||
script { | ||
githubStatus.setPending(this) | ||
} | ||
} | ||
} | ||
stage('Set environment variables'){ | ||
steps { | ||
script { | ||
env.TEST_COMPANY_ID="test" | ||
env.COMPANIES_LIST="test" | ||
} | ||
} | ||
} | ||
stage('Clean') { | ||
steps { | ||
sh 'rm -f *.xml *.log' | ||
} | ||
} | ||
stage('Build Docker images...'){ | ||
steps { | ||
withCredentials([usernameColonPassword(credentialsId: 'EVA-ActivePieces', variable: 'EVA_NPMJS_CREDS')]) { | ||
sh ''' | ||
docker build . --build-arg CREDS=//npm.pkg.github.com/:_authToken=`echo $EVA_BACKEND_CRED | awk -F: '{print $2}'` \ | ||
-t 835065412841.dkr.ecr.eu-west-1.amazonaws.com/''' + projectName + ''':${Env}-latest-`git rev-parse HEAD | cut -c1-7`-${BUILD_NUMBER} | ||
''' | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
success { | ||
script { | ||
githubStatus.setSuccess(this) | ||
} | ||
cleanWs( | ||
deleteDirs: true, | ||
notFailBuild: true, | ||
patterns: [ | ||
[pattern: '.git/**', type: 'EXCLUDE'] | ||
] | ||
) | ||
} | ||
failure { | ||
script { | ||
githubStatus.setFailed(this) | ||
} | ||
} | ||
always { | ||
sh """ | ||
docker logs ${BUILD_TAG} > ${BUILD_TAG}.log 2>&1 || true | ||
docker rmi 835065412841.dkr.ecr.eu-west-1.amazonaws.com/${projectName}:${env.Env}-latest-`git rev-parse HEAD | cut -c1-7`-${BUILD_NUMBER} || true | ||
""" | ||
archiveArtifacts artifacts: '*.log', allowEmptyArchive: true | ||
} | ||
} | ||
} |