Running code in Windows agent but script says we are in Linux

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Running code in Windows agent but script says we are in Linux

judaondo



I have the following pipeline (Jenkinsfile):
@Library('mylib@master')

import com.mylib.*


pipeline {

    agent { label 'WindowsSlaveWS2016' }

    stages {
        stage('Demo') {
            steps {
                echo 'a'
                determineOS()
                echo 'b'
                // sh 'echo "[Version 1.0.0]" | tee -a changelog.txt'
                sayHello()
                //getServiceVersion('.', 'changelog.txt', 'myservice')
                // cat service.properties
                // sendEmail('failed', '[hidden email]')
                script {
                    def utils = new Utils()
                    if (utils.isWindows()) {
                        echo '<-- Is windwos -->'
                    }
                    else {
                        echo '<-- Is linux -->'
                    }
                }
            }
        }
    }

}

determineOS() groovy script is a simple script that does the following:

#!/usr/bin/env groovy

def call() {
    if (System.properties['os.name'].toLowerCase().contains('windows')) {
        println "it's Windows"
    } else {
        println "it's not Windows"
    }
}

and utils.Windows() does the following:

!/usr/bin/groovy

package com.ciplatforms;

class Utils implements Serializable {

def isWindows() {
    if (System.properties['os.name'].toLowerCase().contains('windows')) {
        println "it's Windows"
        return true
    } else {
        println "it's not Windows"
        return false
    }
}

}

I am running the job in a Windows machine as you can notice in the pipeline but the log displays the following:

Running on WindowsSlaveWS2016 in C:\Jenkins\workspace\test-jon-udaondo-pipeline-shared-library
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Demo)
[Pipeline] echo
a
[Pipeline] echo
it's not Windows
[Pipeline] echo
b
[Pipeline] echo
Hello, human.
[Pipeline] script
[Pipeline] {
[Pipeline] echo
<-- Is linux -->
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f71d2b02-9202-4646-8cf0-9d3314be3a65%40googlegroups.com.