-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
145 lines (125 loc) · 5.56 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
pipeline {
agent any
parameters {
booleanParam(name: 'NPM_INSTALL', defaultValue: false, description: 'perform intitial npm install (on package.json update) ?')
//string(name: 'OPT_AMIID', defaultValue: '', description: "mode DEV: lance ansible sur cette ami sans la reconstruire")
}
options {
buildDiscarder(logRotator(numToKeepStr: '15'))
}
// script{
// properties([[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/foo/bar/'], pipelineTriggers([githubPush()])])
// }
// properties([pipelineTriggers([githubPush()])]) //The ‘properties’ section has been renamed as of version 0.8. Use ‘options’ instead
// properties([[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/foo/bar/'], pipelineTriggers([githubPush()])])
stages {
//https://stackoverflow.com/questions/30576881/jenkins-build-when-a-change-is-pushed-to-github-option-is-not-working
// stage('githubPushTrigger'){steps{script{
// properties([[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/benoitrolland/ZoneFactor/'], pipelineTriggers([githubPush()])])
// }}}
stage('Install') {
//checkout
when {
expression { params.NPM_INSTALL ==~ /(?i)(Y|YES|T|TRUE|ON|RUN)/ }
}
steps {
// withCredentials([usernamePassword(credentialsId: 'git-pass-credentials-ID', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
// sh("git checkout master")
// sh("git tag -a some_tag -m 'Jenkins'")
// sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@<REPO> --tags')
// }
// sh 'npm install -g @angular/cli'
sh 'rm -rf node_modules && rm -rf package-lock.json && npm install'
// sh 'npm ci'
}
}
stage('IC') {
steps {
sh 'npm ci'
}
}
stage('Build') {
steps {
// sh 'ng build --prod --env=prod --build-optimizer --source-map'
sh 'ng build --prod --base-href /ZoneFactor/ --env=prod'
}
}
// stage('Deploy') {
//nop parallel{
stage('Deploy on cladone.com') {
when {
branch 'master'
}
steps {
sh 'rm -rf /tmp/host/jenkins/builds/ZoneFactor/'
sh 'mkdir -p /tmp/host/jenkins/builds/ZoneFactor/'
sh 'cp -r ./dist/* /tmp/host/jenkins/builds/ZoneFactor/'
// https://medium.com/@swarnakishore/deploying-angular-cli-project-to-github-pages-db49246598a1
// npm i -g angular-cli-ghpages
// sh 'angular-cli-ghpages --repo=https://GH_TOKEN@github.com/benoitrolland/benoitrolland.github.io --no-silent'
// publication sur les pages github https://github.com/username/username.github.io
// https://www.npmjs.com/package/angular-cli-ghpages
// sh 'npx ngh'
// sh 'cd dist'
// node {
// sh 'git remote add origin ssh://git@github.com/benoitrolland/benoitrolland.github.io.git'
// sh 'git checkout master'
// sh 'git add -A'
// sh 'git commit -m"build $env.BUILD_ID"'
// sh 'echo "terraform -v :"'
// }
sh 'terraform -v'
sh 'echo "pwd: "'
sh 'pwd'
}
}
stage ("Publish to Github pages") {
//git branch: 'master', credentialsId: '84780564-bac0-437e-ad8a-43487fda13fd', url: 'git@github.com:benoitrolland/benoitrolland.github.io.git'
steps {
script {
STAGE_NAME = "Publish to Github pages"
}
// Prepare the workspace
//deleteDir()
//https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/28039894#28039894
//https://stackoverflow.com/questions/33570075/tag-a-repo-from-a-jenkins-workflow-script
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '84780564-bac0-437e-ad8a-43487fda13fd', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
sh '''
echo ""
rm -rf ./benoitrolland.github.io || true
# git clone --depth 1 --no-checkout --single-branch https://github.com/benoitrolland/benoitrolland.github.io.git
git clone --no-checkout --single-branch https://github.com/benoitrolland/benoitrolland.github.io.git
cd benoitrolland.github.io
git config core.sparseCheckout true
#echo "ZoneFactor/*" > .git/info/sparse-checkout
git checkout master
rm -rf ./ZoneFactor/
mkdir ./ZoneFactor/ || true
cp -R /tmp/host/jenkins/builds/ZoneFactor/* ./ZoneFactor/
git status
git add -A
#git add --all
git commit -m "build version number ${env.BUILD_ID}"
git push https://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@github.com/benoitrolland/benoitrolland.github.io.git
'''
//sh "git commit -m \"build version number ${env.BUILD_ID}\""
//sh "git push https://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@github.com/benoitrolland/benoitrolland.github.io.git"
}
//mkdir <repo>
//cd <repo>
//git init
//git remote add -f origin <url>
//git config core.sparseCheckout true
//echo "ZoneFactor/" >> .git/info/sparse-checkout
//git pull origin master
//git init <repo>
//cd <repo>
//git remote add origin <url>
//git config core.sparsecheckout true
//echo "finisht/*" >> .git/info/sparse-checkout
//git pull --depth=1 origin master
}
}
// }}
}
}