pipeline {
    agent any
    tools {
      nodejs 'NodeJs 14'
    }

    environment {
        // Verdaccio 地址
        NPM_REGISTRY_HOST = '192.168.50.67:31766'
    }

    stages {
        stage('Publish') {
            steps {
                withCredentials([
                    usernamePassword(
                        credentialsId: '3495de0a-5574-4345-9a02-371c18314a51',  // Jenkins 中创建的凭证ID
                        usernameVariable: 'NPM_USER',
                        passwordVariable: 'NPM_PASS'
                    )
                ]) {
                    bat '''
                        echo registry=http://%NPM_REGISTRY_HOST%> .npmrc
                        echo //%NPM_REGISTRY_HOST%/:_auth=YWY6Q2xhc3MxMjMhQCE=>> .npmrc
                        echo //%NPM_REGISTRY_HOST%/:always-auth=true>> .npmrc

                        call npm publish --registry http://%NPM_REGISTRY_HOST%
                    '''

                }
            }
        }
    }
}
