Skip to content

Instantly share code, notes, and snippets.

@jasonekratz
Last active September 15, 2022 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonekratz/0424a52fc47202475241eb7b24cecd78 to your computer and use it in GitHub Desktop.
Save jasonekratz/0424a52fc47202475241eb7b24cecd78 to your computer and use it in GitHub Desktop.
Run Jenkins pipeline build using 'sh' step on 64-bit Windows 10

Run Jenkins pipeline build using 'sh' step on 64-bit Windows 10

Test script

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                sh label: '', script: '''#!/bin/bash
                    echo "hello world" 
                '''
            }
        }
    }
}

Jenkins and Windows system configuration

Jenkins

Since the git install is 64-bit both Jenkins and the agent must be running with 64-bit Java. In my case Jenkins is running as a Windows service. Configuration for that service is contained in the file jenkins.xml in the root install folder (in my case c:\jenkins). Jenkins ships with a 32-bit Java VM.

In jenkins.xml need to replace:

<executable>%BASE%\jre\bin\java</executable> with

<executable>C:\Program Files\Java\jre1.8.0_121\bin\java</executable> (need full path to java executable)

Also need to configure the "Shell Executable" in Jenkins UI under "Configure System"

c:\program files\git\git-bash.exe

Need to use the backslash, not the forward slash like usual when using Windows paths in Java applications.

Windows

Also need to add two git folders to the Windows system path:

  • C:\Program Files\Git\bin
  • C:\Program Files\Git\usr\bin

System does not need to be restarted, just restart the Jenkins service.

Useful Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment