0

I have a shell script that using "read" command to get user input when execution like followings:

#!/bin/bash

echo please input Version:
read version

However, when I used jenkins pipeline to execute this script, it directly skipped the user input.

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                dir('/tmp'){
                    sh './Build.sh'
                }
            }
        }
    }
}

The jenkins console log:

[Pipeline] sh
+ ./Build.sh

RootPath : /tmp
please input Version:
release version is null.
[Pipeline] }

How could I pass the "input" to this shell script from Jenkins pipeline? Many thanks.

Tommy Mok
  • 91
  • 10

1 Answers1

0

Could you please try adding a string parameter in the Jenkins. Then you can input the value of the version which can be further used within the Pipeline.

Below link would give more information on how to use https://www.jenkins.io/doc/book/pipeline/syntax/#parameters

Sandeepp
  • 24
  • 3
  • Your shell script will not have access to user input and will fail immediately. This is a duplicate of question: https://stackoverflow.com/a/42502838/366749 – Patrice M. Feb 20 '22 at 02:42
  • I think Jenkins can pass variables to the shell script if it is positional arguments, e.g. `./Build.sh $1' But how about if the script is using "read" command to get user input when it is executing? Do you know how Jenkins can pass the variable to it? – Tommy Mok Feb 22 '22 at 06:30