Skip to content

Instantly share code, notes, and snippets.

@kenanhancer
Last active July 12, 2018 20:29
Show Gist options
  • Save kenanhancer/c3e37fee068408b458b93a93f7f752e3 to your computer and use it in GitHub Desktop.
Save kenanhancer/c3e37fee068408b458b93a93f7f752e3 to your computer and use it in GitHub Desktop.
Jenkinsfile which publish npm package by versioning with BUILD_NUMBER
import org.eclipse.jgit.transport.URIish
def repositoryPath = "kenan.visualstudio.com/DefaultCollection/TestProject/_git/IconSet"
def url = "https://$repositoryPath"
def branch = "master"
def credentialsId = '44995f55-2f49-4cad-905d-b06c32b5e5bd'
node {
stage('Initialize'){
env.NODEJS_HOME = "${tool 'nodejs'}"
// on linux / mac
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: credentialsId, usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
String encoded_gitPassword = java.net.URLEncoder.encode(env.GIT_PASSWORD, "UTF-8")
String gitUserName = java.net.URLEncoder.encode(env.GIT_USERNAME, "UTF-8")
sh "echo \"//npm.dev.btek/:username=${gitUserName}\" >> ~/.npmrc"
sh "echo \"//npm.dev.btek/:_password=${encoded_gitPassword}\" > ~/.npmrc"
}
}
stage('Clone repository') {
/* Let's make sure we have the repository cloned to our workspace */
//checkout scm
git branch: branch, credentialsId: credentialsId, url: url
/*
try {
sh "git checkout -b temp-branch"
} catch(Exception ex) {
sh "git branch -D temp-branch"
sh "git checkout -b temp-branch"
}
*/
//sh "git checkout $branch"
//sh "git merge temp-branch"
//sh "git branch -d temp-branch"
}
stage('Publish Npm Package'){
publishNpmPackage()
}
}
def publishNpmPackage(){
sh "npm set registry http://npm.dev.kenan"
sh "npm version 0.0.1-build$env.BUILD_NUMBER"
sh "npm publish"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment