Get property value from xml file in Jenkinsfile

Viewed 3276

I have a Jenkinsfile in which I need a property from my .csproj file (dotnet core project)

I have tried this:

def versionPrefix = sh(script: 'cat ./src/project.csproj | grep (?<=<VersionPrefix>).*(?=</VersionPrefix>)')

I know I'm probably far off, so I'm not necessarily looking for something close to this, but I am looking for a solution not requiring plugins (preferably).

3 Answers

I know this question has been answered, but if anyone else requires this behaviour and grep -o doesn't work, then the following command can work:

def versionPrefix = sh([returnStdout: true, script: 'sed -n "s/.*<VersionPrefix>\\([^<]*\\)<\\/VersionPrefix>.*/\\1/p" ./src/project.csproj'])

This is because - at least some - grep variants don't support lookaheads/lookbehinds.

Related