
pipeline {
  agent {
    docker {
      image 'docker.internal.justin.tv/devtools/bionic/node12.10.0:latest'
      args '-u root'
    }
  }
  environment {
    NPM_REPO="https://packages.internal.justin.tv/artifactory/api/npm"
  }
  stages {
    stage('build') {
      steps {
        sh 'npm ci'
        sh 'npm run build'
      }
    }
    stage('deploy') {
      when { branch 'main' }
      steps {
        withCredentials([[$class: 'StringBinding', credentialsId: 'dta_tools_deploy', variable: 'DTA_TOOLS_DEPLOY_PASS']]) {
          sh 'curl -udta_tools:$DTA_TOOLS_DEPLOY_PASS $NPM_REPO/auth > ~/.npmrc'
          sh 'echo "email = dta@justin.tv" >> ~/.npmrc'
          sh 'npm publish --registry "$NPM_REPO/ip-npm"'
        }
      }
    }
  }
  post {
    always {
      sh 'git clean -fdx'
    }
  }
}
