Issue
I was probe many options, but nothing function.
For example, I am try to modify the file "test.yaml", changing the text "image:v3" for "image:v4".
I was probe from powershell console directly and is OK, but from Jenkins I receive error: "foreach-object is not recognize as command"
pipeline {
agent any
stages {
stage('MODIFY TEXT') {
steps {
script {
bat 'powershell.exe (get-content D:\\Code\\yamls\\test.yaml) | foreach-object {$_ -replace "image:v3", "image:v4"} | set-content D:\\Code\\yamls\\test.yaml'
}
}
}
}
}
Solution
You should use powershell
(5.x) or pwsh
(7.x) step:
pipeline {
agent any
stages {
stage('MODIFY TEXT') {
steps {
powershell '''
$lines = get-content D:\\Code\\yamls\\test.yaml
$lines | foreach-object {$_ -replace "image:v3", "image:v4"} | set-content D:\\Code\\yamls\\test.yaml
'''
}
}
}
}
Answered By - zett42
Answer Checked By - Marilyn (JavaFixing Volunteer)