1

I am very new to Jenkins and scripting in the pipeline format. I have got my script working and running with TestComplete but the only task I have not managed to get working is Jenkins reporting back in the build description the .exe version run.

The .exe version in the specific folder is always the most recent build so I am trying to target that .exe. I should point out that I can dig into the TestComplete output to see the version tested, but I would be nice to see it on the job dashboard.

Below is a stripped down version if anyone could give some advice

   pipeline {
        agent {
            label 'TestComplete_Runner' 
        }
        options {
        // Only keep the last 1 build
        buildDiscarder(logRotator(numToKeepStr:'1'))
        }
        stages {
            stage('Core_Run') {
                steps {
                    script {
                        def fileVersion = readProperties file:'D:/file/file/file/file.exe'
                        echo "${fileVersion}"
                    }
                    // send build started notifications
                    //slackSend (color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
                }   
            }
        }   
    }
xxxvodnikxxx
  • 1,270
  • 2
  • 18
  • 37
  • 2
    What are you trying to do with `readProperies` on an exe file? It's meant to be used on properties file. – hakamairi Mar 04 '19 at 12:33
  • 2
    Hi, hakamairi is correct, this step is for [java properties](https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html) files - as [docs saying](https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readproperties-read-properties-from-files-in-the-workspace-or-text) - `Reads a file in the current working directory or a String as a plain text Java Properties file. The returned object is a normal Map with String keys. The map can also be pre loaded with default values before reading/parsing the data.` – xxxvodnikxxx Mar 04 '19 at 12:40
  • Ah i see. Is there a method for reading the version of an exe file? – Peter Wilson Mar 04 '19 at 14:42
  • There's no direct method to read the version information in jenkins itself, but [this question and asnwers](https://stackoverflow.com/questions/25648155/windows-command-line-to-read-version-info-of-an-executable-file/45517267) tell you how to accomplish it using some batch script, which can be invoked in a [batch](https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#-bat-%20windows%20batch%20script) section of a pipeline. – Anya Shenanigans Mar 04 '19 at 15:22
  • Thank you for the pointer to that info. – Peter Wilson Mar 04 '19 at 16:36

1 Answers1

1

Powershell way works for me. The trim() is needed to get rid of new line character.

   pipeline {
        agent {
            label 'TestComplete_Runner' 
        }
        stages {
            stage('Core_Run') {
                steps {
                    script {
                        def fileVersion = powershell(returnStdout: true, script: "(Get-Item -path 'D:\\file\\file\\file\\file.exe').VersionInfo.ProductVersion").trim()
                        echo "${fileVersion}"
                    }
                }   
            }
        }   
    }
jing
  • 1,919
  • 2
  • 20
  • 39