Jenkins Pipeline does not store Windows env variables from a cmd file - windows

In a Jenkins Pipeline (groovy) i try to run a windows script and use the variables set in this script afterwards.
I broke down the situation to this Pipeline attached.
Here I call "set" twice. Once before the script and once after the script.
My expectation is that i see the new variable in the second output. But the output does not change at all. I do see some (PATH, ...), so it is not just empty.
The goal is to have scripts working that set for example qt environment variables.
Does anybody know if I call the script in a "bad" manor? or sth else?! that I miss here.
timestamps {
parallel(
"build_windows": {
node('winddk-build') {
stage('create bat file') {
bat """
>mybat.cmd echo set MYVAR=1234
>>mybat.cmd echo cmd /k
"""
}
stage('run bat file') {
bat """
set
cmd /k mybat.cmd
set
"""
}
stage('clean up bat file') {
bat """
del /Q /S mybat.cmd
"""
}
}
}
)
}

Related

How can I echo the value of a windows system variable inside Jenkins pipeline?

For example: when I echo %APPDATA% on cmd line is expected to print the path to appdata folder, like this: "C:\Users\User\AppData". How can I do the same in a jenkins pipeline?
def app1 = "%APPDATA%"
pipeline {
agent any
stages {
stage('Test') {
steps {
echo ¨\¨${app1}\¨"
}
}
}
}
The following methods should work.
echo "${APPDATA}"
echo "${env.APPDATA}"
echo "$APPDATA"

Not seeing script output in Jenkins

I am calling a script from Jenkins pipeline like so:
stage('Prepare Windows') {
steps {
bat '''echo prepare steps on windows'''
bat '''E:\\compass\\preparation\\windows\\prepare_sources.sh juice E:\\builds\\mapps_builds 0.6.0'''
}
}
It works nicely, but the echo statements executed inside the script do not appear in the Jenkins console e.g
echo "=================================="
echo " Preparing build ${BUILD_NUMBER}"
echo "=================================="
I tried:
bat '''E:\\compass\\preparation\\windows\\prepare_sources.sh juice E:\\builds\\mapps_builds 0.6.0 2>&1'''
I have also tried based on the feedback below:
script {
def prepareWindowsStdout = bat(label: 'Prepare Windows Sources', script: "E:\\compass\\preparation\\windows\\prepare_sources.sh juice E:\\builds\\mapps_builds ${env.TRACK}", returnStdout: true)
print prepareWindowsStdout
}
It compiles and runs, but does not print out any output from the bash script.
Any suggestions would be very helpful.
Thanks

Execute shell script from Jenkins Pipeline

I am trying to execute shell script from my jenkins pipeline. I have provided absolute and relative path in the shell command and still I am facing No such file or directory error while building the pipeline.
This is simple script but yet not working.
Try 1:
stage ( 'Executing shell script' ) {
steps {
sh '/home/patching/shell_script.sh'
}
}
Try 2:
stage ( 'Executing shell script' ) {
steps {
sh './shell_script.sh'
}
}
Try 3:
stage ( 'Executing shell script' ) {
steps {
dir ('/home/patching/shell_script.sh){
sh './shell_script.sh'
}
}
I really don't know what is really wrong with the script. Could some one help me on this?
I got the issue why it wasn't able to find the file that I wanted to run. It was running on different slave.
Can you try this
pipeline {
agent any
stages {
stage('Hello World') {
steps {
script {
sh '''
/home/ubuntu/First.sh
'''
}
}
}
}
}

Shell script not running from jenkins file

When I run the shell script from the Jenkins File in my windows machine
I am getting an error saying
---"Cannot run program "nohup" (in directory "C:\Program Files (x86)\Jenkins\workspace\testjf_master"): CreateProcess error=2, The
system cannot find the file specified"
Sh command is running from my cmd, so I guess right path defined in ENV
pipeline {
agent any
stages {
stage('stage A') {
steps {
echo 'this is stage A, my demo value is $demo'
sh 'echo "this is $BUILD_NUMBER of demo $demo"'
}
}
}
environment {
demo = '08'
}
}

OutPut of an EXE application in Command or Batch

I have a simple Console application which returns a int value out ,
when i run this application from command , How do i capture the Out put ?
Code
static int Main(string[] args)
{
return 1;
}
I used the following line of Command
for /f %a in ('D://Test//ConsoleApplication1//ConsoleApplication1//bin//Debug//ConsoleApplication1.exe') do set "dow=%a"
When i output echo %dow% , it prints what is in front of echo and not the value .
You can create bat file next to your exe file and write inside bat this:
YourExeApp.exe > d:\test.txt
Don´t use C:\test.txt directly. Use rather C:\test\test.txt

Resources