0

I use "free style project" to get build of my project. I select "This project is parameterized" and define "choice parameter". Project choice parameter

Then i define build step which has string match condition with ${Project} build parameter.

Build gives error with following console output:

Run condition [Strings match] enabling prebuild for step [BuilderChain] Exception caught evaluating condition: [org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'Project' in '${Project}'], action = [Fail]

How can i use build parameter with logical build conditons.

Alan
  • 589
  • 5
  • 29
Mehmet
  • 1
  • 4

1 Answers1

0

Be sure its not something related with this Other question

Otherwise you can use plugin Conditional Build Step plugin to compare if your parameter matches a string, and it should work fine as you use it with ${Project}. If you are using parameter on a another kind of build step like 'Execute shell command' or 'Execute shell command on Windows' use ${Project}on *nix systems and %Project%for Windows systems

Another way (that works) to get a build parameter and compare it to a string if you are using a pipeline:

pipeline {
  agent any
  parameters{
      choice(
        choices: 'PROJECT_1\nPROJECT_2',
        description: 'Select the project',
        name: 'Project')
  }
  stages {
      stage ('Test stage') {
          when {
              expression { params.Project == 'PROJECT_1' }
          }
          steps {
              echo "IT IS PROJECT 1"
          }
      }
  }
}
CMassa
  • 91
  • 4
  • I install "Conditional Build Step plugin" and it works, thank you. But ${xxx} format does not work with windows installation and "Execute windows batch command" step. I also tried with container installation which comes with linux "execute shell" step, it worked. – Mehmet Aug 22 '18 at 02:49
  • If you are using "Execute windows batch command", paramaters have to be used with the syntax %PARAMETER%, syntax with $ is for *nix systems. – CMassa Aug 22 '18 at 07:33