I have a Jenkinsfile which analyses some local artifactory server for new versions of the parent and dependencies. When I confirm that there is a new version, I want to replace the old version with a new one.
so given a pom.xml containing this dependency:
<dependency>
<groupId>abcde</groupId>
<artifactId>xyz</artifactId>
<version>1.2.4</version>
</dependency>
... and assume that there is a newer version 1.3.5 of abcde.xyz ...
I would like to update that with the following sed command:
sed -i '/<dependency>/,/<\/dependency>/{
/<groupId>abcde<\/groupId>/{
/<artifactId>xyz<\/artifactId>/{
s/<version>1.2.4<\/version>/<version>1.3.5<\/version>/
}
}
}' pom.xml
If I create a pom.xml either containing the above xml or only the above xml and execute this statement, the file is modified, but nothing changes. removing the -i flag basically dumps the file 1:1 to stdout - what am I missing?
expected output:
<dependency>
<groupId>abcde</groupId>
<artifactId>xyz</artifactId>
<version>1.3.5</version>
</dependency>
(In the jenkinsfile it is parameterized and escaped like below, but since the basic statement is not working, please focus on that.)
sh """
sed -i '/<dependency>/,/<\\/dependency>/{
/<groupId>${groupId}<\\/groupId>/{
/<artifactId>${artifactId}<\\/artifactId>/{
s/<version>${version}<\\/version>/<version>${targetVersion}<\\/version>/
}
}
}' pom.xml
"""