I'm pretty new to groovy.In my Jenkinsfile
i am trying to store a windows cmd output in a variable, use it in the next command, but nothing seems to be working. This is the closest i got:
pipeline {
agent any
stages {
stage('package-windows') {
when {
expression { isUnix() == false}
}
steps {
script {
FILENAME = bat(label: 'Get file name', returnStdout: true, script:"dir \".\\archive\\%MY_FOLDER%\\www\\main.*.js\" /s /b")
}
bat label: 'replace content', script: "powershell -Command \"(gc \"$FILENAME\") -replace \"https://my-qa.domain.com/api/\", \"https://my-prod.domain.com/api/\" | Out-File \"$FILENAME\"\""
}
}
}
}
When i do ECHO "$FILENAME"
this is the output i am getting:
C:\Program Files (x86)\Jenkins\workspace\my-ui>dir ".\archive\55131c0d3c28dc69ce39572eaf2f8585996d9108\main.*.js" /s /b
C:\Program Files (x86)\Jenkins\workspace\my-ui\archive\55131c0d3c28dc69ce39572eaf2f8585996d9108\www\main.16aedaf4c6be4e47266d.js
All i need is the file name main.16aedaf4c6be4e47266d.js
to be used in the next command to modify the contents. But in the next command "$FILENAME"
is empty. How can i store the command output in a variable correctly and access in the next commands ?