kubesphere的devops指定nodej的版本

因为前端项目是vue的,这个vue项目需要的nodejs的版本比较高,而且以前的项目用的vue版本正合适

所以需要指定nodejs的版本,具体的配置如下:

其中官网的nodej版本没有docker所以下面的的container应该用base不应该用nodejs,否则会提示找不到docker

pipeline {
   agent {
    kubernetes {
      inheritFrom 'nodejs base'
      containerTemplate {
        name 'nodejs'
        image 'node:14.19.0'
      }

    }
  }
  stages {
    stage('拉取代码') {
      agent none
      steps {
        container('nodejs') {
          checkout(scm: [$class: 'SubversionSCM', locations: [[cancelProcessOnExternalsFail: true,  credentialsId: 'svn', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://10.18.1.2:9011/svn/HiEdu1.0/trunk/src/app/avue-data@HEAD']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']], poll: false)
          sh 'ls'
          sh 'pwd'
        }

      }
    }
 stage('项目编译') {
      agent none
      steps {
        container('nodejs') {
          sh '''
           
            npm install
            npm run build
            pwd
            ls
            '''
        }

      }
    }
    stage('构建镜像') {
      agent none
      steps {
        container('base') {
          sh 'docker build -f Dockerfile  -t avue-data:$versition  .'
        }

      }
    }

    stage('推送镜像') {
      agent none
      steps {
        container('base') {
          withCredentials([usernamePassword(credentialsId : 'docker-local' ,passwordVariable : 'DOCKER_PWD_VAR' ,usernameVariable : 'DOCKER_USER_VAR' ,)]) {
            sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
            sh 'docker tag avue-data:$versition $REGISTRY/$DOCKERHUB_NAMESPACE/avue-data:$versition'
            sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/avue-data:$versition'
          }

        }

      }
    }

    stage('deploy to dev') {
      agent none
      steps {
        container('base') {
          withCredentials([kubeconfigContent(credentialsId : 'k8s-config' ,variable : 'KUBECONFIG_CONTENT' ,)]) {
            sh '''mkdir ~/.kube
echo "$KUBECONFIG_CONTENT" > ~/.kube/config
envsubst < deploy/avue-data.yaml | kubectl apply -f -'''
          }

        }

      }
    }

  }
  environment {
    DOCKER_CREDENTIAL_ID = 'dockerhub-id'
    GITHUB_CREDENTIAL_ID = 'github-id'
    KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
    REGISTRY = 'registry.kubeoperator.io:8083'
    DOCKERHUB_NAMESPACE = 'hiedu'
    GITHUB_ACCOUNT = 'kubesphere'
    APP_NAME = 'devops-java-sample'
  }
  options {
    timeout(time: 1, unit: 'HOURS')
  }
  parameters {
    string(name: 'versition', defaultValue: 'v20.0', description: '版本号')
  }
}