-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from dario-rodriguez/cicd-and-deployment
Cicd and deployment
- Loading branch information
Showing
31 changed files
with
615 additions
and
43 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
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
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
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
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
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
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
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
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
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
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
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
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,28 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<flow-definition plugin="[email protected]"> | ||
<description></description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties/> | ||
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="[email protected]"> | ||
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]"> | ||
<configVersion>2</configVersion> | ||
<userRemoteConfigs> | ||
<hudson.plugins.git.UserRemoteConfig> | ||
<url>https://github.com/dario-rodriguez/my-thai-star.git</url> | ||
</hudson.plugins.git.UserRemoteConfig> | ||
</userRemoteConfigs> | ||
<branches> | ||
<hudson.plugins.git.BranchSpec> | ||
<name>*/cicd-and-deployment</name> | ||
</hudson.plugins.git.BranchSpec> | ||
</branches> | ||
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> | ||
<submoduleCfg class="list"/> | ||
<extensions/> | ||
</scm> | ||
<scriptPath>jenkins/angular/cicd/Jenkinsfile</scriptPath> | ||
<lightweight>true</lightweight> | ||
</definition> | ||
<triggers/> | ||
<disabled>false</disabled> | ||
</flow-definition> |
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 @@ | ||
pipeline{ | ||
agent any | ||
|
||
options { | ||
buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '5', numToKeepStr: '50')) | ||
// Disable concurrent builds. It will wait until the pipeline finish before start a new one | ||
disableConcurrentBuilds() | ||
} | ||
|
||
environment { | ||
// Jenkins credentials id for ssh agent | ||
sshAgentCredentials = '3d0fa2a4-5cf0-4cf5-a3fd-23655eb33c11' | ||
|
||
// Nexus3 API url | ||
nexusApiUrl = 'devon.s2-eu.capgemini.com/nexus3/' | ||
// Maven repository | ||
repository = 'snapshots' | ||
// Repository format | ||
format = 'maven2' | ||
// Artifact group | ||
group = 'com.devonfw.mythaistar' | ||
// Application name | ||
name = 'mythaistar-restaurant' | ||
// Artifact extension | ||
extension = 'zip' | ||
} | ||
|
||
parameters { | ||
string(name: 'VERSION', defaultValue: '1.12.0-SNAPSHOT', description: 'Version number') | ||
string(name: 'EXTERNAL_SERVER_IP', defaultValue: '10.40.235.244', description: 'Server IP') | ||
string(name: 'APPLICATION_DIR', defaultValue: '/root/mythaistar/reverse-proxy/', description: 'My Thai Star application directory') | ||
} | ||
|
||
stages { | ||
stage ('Download artifact from Nexus') { | ||
steps { | ||
script { | ||
// Download artifact from nexus3 using the nexus3 beta api | ||
withCredentials([usernamePassword(credentialsId: 'pl-technical-user', passwordVariable: 'pass', usernameVariable: 'user')]) { | ||
// Search the list of artifacts | ||
def response = httpRequest """https://${user}:${pass}@${nexusApiUrl}service/rest/beta/search/assets?repository=${repository}&format=${format}&group=${group}&name=${name}&maven.groupId=${group}&maven.artifactId=${name}&maven.baseVersion=${params.VERSION}&maven.extension=${extension}""" | ||
def props = readJSON text: response.content | ||
|
||
// Get the last snapshot download url | ||
def num = -1 | ||
def url = '' | ||
props.items.each { | ||
def n = (it.downloadUrl =~ /.*-(\d*)\.zip/)[0][1] | ||
if (n > num) { | ||
num = n | ||
url = it.downloadUrl | ||
} | ||
} | ||
|
||
// Download the snapshot | ||
sh """wget -O ${name}-${params.VERSION}.${extension} ${url.replace('https://','https://'+user+':'+pass+'@')}""" | ||
|
||
// Unzip the angular application | ||
sh "mkdir -p dist" | ||
unzip dir: 'dist', zipFile: """${name}-${params.VERSION}.${extension}""" | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage ('Deployment') { | ||
steps { | ||
script { | ||
dir('dist'){ | ||
sshagent (credentials: [sshAgentCredentials]) { | ||
sh """ | ||
# Copy resulting "dist" folder from workspace to deployment server | ||
ssh -o StrictHostKeyChecking=no root@${params.EXTERNAL_SERVER_IP} mkdir -p ${params.APPLICATION_DIR}angular/dist/ | ||
ssh -o StrictHostKeyChecking=no root@${params.EXTERNAL_SERVER_IP} rm -r ${params.APPLICATION_DIR}angular/dist/* 2> /dev/null | ||
scp -o StrictHostKeyChecking=no -r . root@${params.EXTERNAL_SERVER_IP}:${params.APPLICATION_DIR}angular/dist/ | ||
# Launch application in Docker container | ||
ssh -o StrictHostKeyChecking=no root@${params.EXTERNAL_SERVER_IP} docker-compose -f ${params.APPLICATION_DIR}docker-compose.yml up -d --build | ||
""" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
post { | ||
always { | ||
cleanWs() | ||
} | ||
} | ||
} |
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,28 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<flow-definition plugin="[email protected]"> | ||
<description></description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties/> | ||
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="[email protected]"> | ||
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]"> | ||
<configVersion>2</configVersion> | ||
<userRemoteConfigs> | ||
<hudson.plugins.git.UserRemoteConfig> | ||
<url>https://github.com/dario-rodriguez/my-thai-star.git</url> | ||
</hudson.plugins.git.UserRemoteConfig> | ||
</userRemoteConfigs> | ||
<branches> | ||
<hudson.plugins.git.BranchSpec> | ||
<name>*/cicd-and-deployment</name> | ||
</hudson.plugins.git.BranchSpec> | ||
</branches> | ||
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> | ||
<submoduleCfg class="list"/> | ||
<extensions/> | ||
</scm> | ||
<scriptPath>jenkins/deployment/cicd/Jenkinsfile</scriptPath> | ||
<lightweight>true</lightweight> | ||
</definition> | ||
<triggers/> | ||
<disabled>false</disabled> | ||
</flow-definition> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.