1. npm config get registry // 查看npm当前镜像源
    2. npm config set registry https://registry.npmjs.org
    3. yarn config get registry // 查看yarn当前镜像源
    4. yarn config set registry https://registry.yarnpkg.com
    1. pipeline {
    2. agent {
    3. node {
    4. label 'nodejs'
    5. }
    6. }
    7. parameters {
    8. string(name:'TAG_NAME', defaultValue: '', description:'')
    9. }
    10. options {
    11. buildDiscarder(logRotator(numToKeepStr: '5'))
    12. quietPeriod(5)
    13. timeout(time: 20, unit: 'MINUTES')
    14. }
    15. environment {
    16. HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
    17. KUBECONFIG_CREDENTIAL_ID = 'pipeline-user-kubeconfig'
    18. APP_NAME = 'scp-ui-web'
    19. }
    20. stages {
    21. stage ('checkout scm') {
    22. steps {
    23. checkout(scm)
    24. script {
    25. sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/docker/vue/Dockerfile'
    26. }
    27. }
    28. }
    29. stage ('build develop') {
    30. when {
    31. branch 'develop'
    32. }
    33. environment {
    34. HARBOR_HOST = 'bytest-harbor.ur.com.cn'
    35. HARBOR_NAMESPACE = 'scp-dev'
    36. HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
    37. }
    38. steps {
    39. container('nodejs') {
    40. sh '''
    41. yarn config set ignore-engines true
    42. yarn config set registry https://registry.npmmirror.com
    43. yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
    44. yarn config get registry
    45. yarn cache dir
    46. '''
    47. sh 'yarn install --frozen-lockfile'
    48. sh 'yarn build:new'
    49. sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER .'
    50. withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
    51. sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
    52. sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER'
    53. }
    54. }
    55. }
    56. }
    57. stage ('build test') {
    58. when {
    59. branch 'test'
    60. }
    61. environment {
    62. HARBOR_HOST = 'bytest-harbor.ur.com.cn'
    63. HARBOR_NAMESPACE = 'scp-test'
    64. HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
    65. }
    66. steps {
    67. container('nodejs') {
    68. sh '''
    69. yarn config set ignore-engines true
    70. yarn config set registry https://registry.npmmirror.com
    71. yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
    72. yarn config get registry
    73. yarn cache dir
    74. '''
    75. sh 'yarn install --frozen-lockfile'
    76. sh 'yarn build:new'
    77. sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER .'
    78. withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
    79. sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
    80. sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER'
    81. }
    82. }
    83. }
    84. }
    85. stage ('build pre') {
    86. when {
    87. branch 'pre'
    88. }
    89. environment {
    90. HARBOR_HOST = 'hw-harbor.ur.com.cn'
    91. HARBOR_NAMESPACE = 'scp-pre'
    92. HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
    93. }
    94. steps {
    95. container('nodejs') {
    96. sh '''
    97. yarn config set ignore-engines true
    98. yarn config set registry https://registry.npmmirror.com
    99. yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
    100. yarn config get registry
    101. yarn cache dir
    102. '''
    103. sh 'yarn install --frozen-lockfile'
    104. sh 'yarn build:new'
    105. sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER .'
    106. withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
    107. sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
    108. sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER'
    109. }
    110. }
    111. }
    112. }
    113. stage ('build release') {
    114. when {
    115. tag 'release-*'
    116. }
    117. environment {
    118. HARBOR_HOST = 'hw-harbor.ur.com.cn'
    119. HARBOR_NAMESPACE = 'scp-prod'
    120. HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
    121. }
    122. steps {
    123. container('nodejs') {
    124. sh '''
    125. yarn config set ignore-engines true
    126. yarn config set registry https://registry.npmmirror.com
    127. yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
    128. yarn config get registry
    129. yarn cache dir
    130. '''
    131. sh 'yarn install --frozen-lockfile'
    132. sh 'yarn build:new'
    133. sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME-$BUILD_NUMBER .'
    134. withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
    135. sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
    136. sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME-$BUILD_NUMBER'
    137. }
    138. }
    139. }
    140. }
    141. stage('deploy to develop') {
    142. when {
    143. branch 'develop'
    144. }
    145. environment {
    146. NAMESPACE = 'scp-dev'
    147. HARBOR_HOST = 'bytest-harbor.ur.com.cn'
    148. HARBOR_NAMESPACE = 'scp-dev'
    149. }
    150. steps {
    151. container ('nodejs') {
    152. withCredentials([
    153. kubeconfigFile(
    154. credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
    155. {
    156. sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/dev/deployment.yaml'
    157. sh 'envsubst < `pwd`/deployment.yaml | cat -'
    158. sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
    159. }
    160. }
    161. }
    162. }
    163. stage('deploy to test') {
    164. when {
    165. branch 'test'
    166. }
    167. environment {
    168. NAMESPACE = 'scp-test'
    169. HARBOR_HOST = 'bytest-harbor.ur.com.cn'
    170. HARBOR_NAMESPACE = 'scp-test'
    171. }
    172. steps {
    173. container ('nodejs') {
    174. withCredentials([
    175. kubeconfigFile(
    176. credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
    177. {
    178. sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/dev/deployment.yaml'
    179. sh 'envsubst < `pwd`/deployment.yaml | cat -'
    180. sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
    181. }
    182. }
    183. }
    184. }
    185. stage('deploy to pre') {
    186. when {
    187. branch 'pre'
    188. }
    189. environment {
    190. NAMESPACE = 'scp-pre'
    191. HARBOR_HOST = 'hw-harbor.ur.com.cn'
    192. HARBOR_NAMESPACE = 'scp-pre'
    193. }
    194. steps {
    195. container ('nodejs') {
    196. withCredentials([
    197. kubeconfigFile(
    198. credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
    199. {
    200. sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/pre/deployment.yaml'
    201. sh 'envsubst < `pwd`/deployment.yaml | cat -'
    202. sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
    203. }
    204. }
    205. }
    206. }
    207. stage ('deploy release') {
    208. when {
    209. tag 'release-*'
    210. }
    211. environment {
    212. NAMESPACE = 'scp-prod'
    213. HARBOR_HOST = 'hw-harbor.ur.com.cn'
    214. HARBOR_NAMESPACE = 'scp-prod'
    215. }
    216. steps {
    217. container ('nodejs') {
    218. withCredentials([
    219. kubeconfigFile(
    220. credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
    221. {
    222. sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/prod/deployment.yaml'
    223. sh 'envsubst < `pwd`/deployment.yaml | cat -'
    224. sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
    225. }
    226. }
    227. }
    228. }
    229. }
    230. }