Jenkinsfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. pipeline {
  2. agent {
  3. node {
  4. label 'nodejs'
  5. }
  6. }
  7. stages {
  8. stage('clone code') {
  9. agent none
  10. steps {
  11. container('nodejs') {
  12. git(url: 'http://gitlab.yinbin.ink:30000/test/yygh-site.git', credentialsId: 'nas-gitlab', branch: 'master', changelog: true, poll: false)
  13. }
  14. }
  15. }
  16. stage('build js') {
  17. agent none
  18. steps {
  19. container('nodejs') {
  20. sh 'npm i --registry=https://registry.npmmirror.com'
  21. sh 'npm run build'
  22. }
  23. }
  24. }
  25. stage('build & push') {
  26. agent none
  27. steps {
  28. container('nodejs') {
  29. sh 'docker build -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:v$BUILD_NUMBER .'
  30. withCredentials([usernamePassword(credentialsId : 'harbor-docker-registry' ,usernameVariable : 'DOCKER_REGISTY_USER' ,passwordVariable : 'DOCKER_REGISTY_PASSWD' ,)]) {
  31. sh '''
  32. echo "$DOCKER_REGISTY_PASSWD" | docker login $REGISTRY -u "$DOCKER_REGISTY_USER" --password-stdin
  33. '''
  34. sh '''
  35. docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:v$BUILD_NUMBER'''
  36. }
  37. }
  38. }
  39. }
  40. stage('deploy to production') {
  41. steps {
  42. kubernetesDeploy(configs: 'deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
  43. }
  44. }
  45. }
  46. environment {
  47. DOCKER_CREDENTIAL_ID = 'dockerhub-id'
  48. GITHUB_CREDENTIAL_ID = 'github-id'
  49. KUBECONFIG_CREDENTIAL_ID = 'kubeconfig-dev-id'
  50. REGISTRY = '192.168.122.10:30002'
  51. DOCKERHUB_NAMESPACE = 'devops_syt'
  52. GITHUB_ACCOUNT = 'kubesphere'
  53. APP_NAME = 'yygh-site'
  54. }
  55. }