Shell command to update pom file from a variable

后端 未结 6 1500
[愿得一人]
[愿得一人] 2021-01-06 17:24

Previously I used below command to take the version in pom.xml and increment it from one. Before increment snapshot version is, 0.0.1

#!/bin/bas         


        
6条回答
  •  无人及你
    2021-01-06 18:17

    I can use maven plugin to do above increment. But the thing is my mentor has been instructed me to get it by using shell commands for practice shell scripting. I highly appreciate your support. Somehow I solved my question using below commands.

    #!/bin/bash
    
    cd Project/
    
    version=$(grep -ri "" pom.xml |head -n 1 | sed -e 's/^[ \t]*\ 
    ([^<]*\)<.*$/\1/')
    
    major=$(echo $version | cut -c1)
    var2=$(echo $version | cut -c2)
    miner=$(echo $version | cut -c3)
    var4=$(echo $version | cut -c4)
    bug=$(echo $version | cut -c5)
    bug=$((bug+1))
    str="-SNAPSHOT"
    incrementVer=$major$var2$miner$var4$bug$str
    echo $incrementVer
    
    pomChange=$(grep -ri "" pom.xml | head -n 1 | sed -i "s/\(\)[^<]*\ 
    (<\/version>\)/\1$incrementVer\2/" pom.xml)
    echo $pomChange
    

    Output looks like,

    [INFO] ------------------------------------------------------------------- 
    [INFO] BUILD SUCCESS
    [INFO] --------------------------------------------------------------------- 
    [INFO] Total time: 4.087s
    [INFO] Finished at: Wed Oct 31 00:25:40 IST 2018
    [INFO] Final Memory: 6M/17M
    [INFO] --------------------------------------------------------------------
    0.0.2-SNAPSHOT
    Finished: SUCCESS
    

提交回复
热议问题