0

I am facing a strange issue, I have a piece of code written in groovy and contains a shell script to update the values of variables in system.properties file. Most of the times the script works fine, but 20% of the times it deletes all the file content instead of updating the variables

def call(credentialsId, repoName, repoAddress, variableToUpdate, releaseType, BRANCH_NAME, branchToCheckoutInRepo, OS='linux'){
    def now = new Date()

            sh """
            cat system.properties | sed -e 's@${variableToUpdate}=.*@${variableToUpdate}=${BRANCH_NAME}@g; s@releaseType=.*@releaseType=${releaseType}@g; s@lastModified=.*@lastModified="${now}"@g' | tee system.properties
        """

}```
jww
  • 97,681
  • 90
  • 411
  • 885
  • See this: https://stackoverflow.com/questions/6696842/how-can-i-use-a-file-in-a-command-and-redirect-output-to-the-same-file-without-t – not exactly the same, but same problem. `tee` truncates the file before `cat` gets to see it. – Benjamin W. Jun 13 '19 at 13:41
  • Solution for you: just `sed -i system.properties`. – KamilCuk Jun 13 '19 at 13:43
  • 3
    Using external tools from Python for this is completely wacky anyway. Look at `fileinput.input(inplace=True)` – tripleee Jun 13 '19 at 13:46
  • @KamilCuk can you please mention the complete command here. Thanks – Sheikh Ozair Bilal Jun 16 '19 at 05:28
  • `sed -i -e 's@${variableToUpdate}=.*@${variableToUpdate}=${BRANCH_NAME}@g; s@releaseType=.*@releaseType=${releaseType}@g; s@lastModified=.*@lastModified="${now}"@g' system.properties` ? – KamilCuk Jun 16 '19 at 08:57
  • @KamilCuk thanks I'll try and mark ticket as resolved! – Sheikh Ozair Bilal Jun 17 '19 at 05:52

0 Answers0