[英]How to update version number of package.json file automatically
I have a requirement for upgrading the package.json
version automatically through jenkins.我需要通过 jenkins 自动升级package.json
版本。 We have the node project which will build through Jenkins, everything is fine but when we want to upgrade version
in package.json
everytime we need to manually make changes in package.json and then push to Jenkins through GitLab.我们有将通过 Jenkins 构建的节点项目,一切都很好,但是当我们想要升级package.json
version
,每次我们需要手动在 package.json 中进行更改,然后通过 GitLab 推送到 Jenkins。
Is there any way to automate this step??有没有办法自动化这一步?
Here is Jenkinsfile这是詹金斯文件
pipeline {
agent any
stages {
stage('Build') {
steps {
checkout([$class: 'GitSCM', branches: [[name: 'master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'ID', url: 'https://gitlab.com/company/website.git']]])
sh "pwd"
sh "npm install"
sh "npm run build"
}
}
stage('deploy') {
steps {
sh "scp -v -o StrictHostKeyChecking=no -r /var/lib/jenkins/workspace/project/build/* ubuntu@prod:/var/www/project/"
}
}
}
}
Here is package.json file这是 package.json 文件
"name": "my-project",
"version": "1.1.24",
"description": "web application",
"main": "index.js",
"repository": "https://gitlab.com/",
"private": true,
Issue is resolved with awk command line tool in linux问题已通过 linux 中的 awk 命令行工具解决
#!/usr/bin/awk
awk -F'["]' -v OFS='"' '/"version":/{split($4,a,".");$4=a[1]+1"."a[2]"."a[3]+1};1' ./package.json > ./package2.json && mv ./package2.json ./package.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.