简体   繁体   English

如何自动更新 package.json 文件的版本号

[英]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.

相关问题 自动更新 package.json 版本 - update package.json version automatically 如何使用`npm update`更新package.json中的所有包版本号? - how to update all package version number in package.json when use `npm update`? 如何在 Jenkinsfile 中使用 package.json 的版本号自动重命名“dist”文件夹 - How to rename 'dist' folder with version number of package.json automatically in Jenkinsfile 如何将 package.json 更新到每个 package 的最新版本? - How to update package.json to latest version of each package? npm更新不是更新package.json文件中的版本 - npm update is not updating the version in package.json file 如何自动更新 package.json 中的条目? - How do I update the entries in package.json automatically? 在NodeJS应用程序中自动更新package.json - Automatically Update the package.json in NodeJS application 如何使用Jenkins在package.json中自动化版本号 - How to Automate version number in package.json with Jenkins 如何将package.json中的各个依赖更新到最新版本? - How to update each dependency in package.json to the latest version? 如何使用 npm 将 package-lock.json 和/或 package.json 中的包版本更新到最新版本? - How to update version of a package in package-lock.json and/or package.json using npm to latest version?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM