Search code examples
batch-filejenkinsjenkins-agent

How to execute windows batch file in windows slave agent from jenkins console


I am a newbie wrt jenkins. So I am sorry if this question is so naive. I would like to execute batch file on windows slave agent from jenkins project/job. Please let me know how to achieve the same.

Following is the log for the same.

Started by user Jenkins Admin Building remotely on slave01 in workspace d:\jenkins\workspace\Test Triggering Test � default Test � default completed with result FAILURE Finished: FAILURE


Solution

  • For Freestyle Project:-

    Go to the configure option of the job and follow below (provide the Label of your agent in the Label Expression)

    enter image description here

    and select the Execute Windows batch command in configure

    enter image description here For Pipeline Project:-

    Use the below snippet in the jenkins file

    stage ('Build') {
                steps {
                    node(label: 'AgentName') {
                            bat "batch script location"
                        }
                    }
                }