[Solved] Jenkins role strategy plugin and restrict user to build if not in proper group — Jenkins file

Savke Asks: Jenkins role strategy plugin and restrict user to build if not in proper group — Jenkins file
We have two environments, qa and dev, and that is configured as parameters in Jenkinsfile. Plugin Role-based Authorization Strategy is enabled, and there are two groups of users, qa and dev (same as environment). The problem here is that qa users can start to build jobs with dev environment. Is there any way that we restrict this behavior? Here is a simple example:

Code:
pipeline {
    agent any 
     
    choice(name: 'environment', choices: ['dev', 'qa']

    stages {    
        stage('test') { 
            script {
              if (params.environment == 'dev' && env.BUILD_USER_ID not in env.BUILD_USER_GROUPS) {echo "User ${env.BUILD_USER_ID} can not start build on DEV enviroment"}
              else if (params.environment == 'qa' && env.BUILD_USER_ID not in env.BUILD_USER_GROUPS) {echo "User ${env.BUILD_USER_ID} can not start build on QA enviroment"}
              else {echo "You can run job, You are in proper group for this enviroment"}
        } 
      }                     
    }
  }

An example is not real, and maybe not working, but I hope that can be understood what I want to accomplish.

P.S. Documentation for this is not so good, and also can’t find much more examples on web.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.