Jenkins 声明式管道 - 脚本无法将参数作为变量获取

Jenkins Declarative Piplines- Script is unable to pickup parameter as varible

我是 Jenkins 的新手。尝试创建一个使用基于选择的参数的基本管道。以下是我的脚本。

代码----

  pipeline{
     agent {
        label 'agent'
           } 
     parameters {
        choice choices: ['John', 'Stacy'], description: 'Choose one', name: 'Person'
         }
     stages {
        stage('Print') {
            steps {
               echo "Hello ${params.Person}"
               sh """if (${params.Person} = "John")
                     then
                       echo "Person is male."
                     else
                        echo "Person is female."
                     fi"""
                }
                    }
     } 
  }

现在,无论我选择什么选项,我的构建都已成功完成。它总是显示结果“人是女性。

以下是我的一个构建结果。

Started by user ****
[Pipeline] Start of Pipeline
[Pipeline] node
Running on agent in 
 /home/temp/jenkins_agent/workspace/ChoiceBased PL
 [Pipeline] {
 [Pipeline] stage
 [Pipeline] { (Print)
 [Pipeline] echo
 Hello John
 [Pipeline] sh
 + John = John
  /home/temp/jenkins_agent/workspace/ChoiceBased PL@tmp/durable- 
 b7e98c46/script.sh: 1: John: not found
 + echo Person is female.
 Person is female.
 [Pipeline] }
 [Pipeline] // stage
 [Pipeline] }
 [Pipeline] // node
 [Pipeline] End of Pipeline

已完成:成功

请指出我遗漏了什么?

我会改变这个只是为了在 Groovy 中而不是在 sh

中进行比较
    stage('Print') {
        steps {
           echo "Hello ${params.Person}"
           script {
               if (params.Person == "John") {
                   echo "Person is male."
               } else {
                   echo "Person is female."
               }
            }
        }
    }

那么当你选择Stacey时你会得到

[Pipeline] echo
Hello Stacy
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Person is female.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS