- 1 year ago
How to run batch script in a Jenkins pipeline building on a Windows-based Kubernetes pod
To run a batch script in a Jenkins pipeline building on a Windows-based Kubernetes pod, you can use the following steps:
Set up a Kubernetes pod with Windows as the operating system. You can create a Kubernetes pod with Windows by specifying the
windows
image in the pod's container specification.Install the Jenkins agent on the Kubernetes pod. You can use the
kubectl
command-line tool to create a Jenkins agent pod with the appropriate configuration.Create a Jenkins pipeline that executes the batch script. You can use the
bat
command in the Jenkins pipeline script to run the batch script.
Here's an example Jenkins pipeline script that runs a batch script:
pythonpipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
app: jenkins-agent
spec:
containers:
- name: jnlp
image: jenkins/jnlp-slave:latest-windows
restartPolicy: Never
"""
}
}
stages {
stage('Run Batch Script') {
steps {
bat 'c:\\path\\to\\batch\\script.bat'
}
}
}
}
In this example, the Jenkins agent is set up on a Windows-based Kubernetes pod using the jenkins/jnlp-slave
image. The bat
command is used to execute the batch script located at c:\path\to\batch\script.bat
.
Note that the path to the batch script may vary depending on your specific setup. You may need to modify the script path to match the location of your batch script.