jenkins hide certain build parameters from general users - jenkins

I have a project based security enabled for my jobs. And based on user being admin / non-admin would like to show / hide certain build parameters.
Can anyone suggest an approach to tackle this requirements or are there any plugins for this?
Thanks!! Appreciate your help on this.

I don't think there is such a feature directly, but there is a workaround.
Configure "non-admin" job with only the parameters that non-admins should see.
Give that job security so that non-admins can build it.
Configure second "admin" job
Give that second job security so that only admins can build it.
In the Job Configuration of the second "admin" job, you need to:
Define all parameters (admin and non-admin)
Use Parameterized Trigger plugin ("Trigger/call builds on other projects" build action) to trigger "non-admin" job
Configure Add Parameters -> Current build parameters
That's it.
In the Job Configuration of the first "non-admin" job, you need to:
Define just non-admin parameters, making sure their names are exactly same as overlapping parameters from "admin" job
Configure the rest of the job as you normally would.
All parameters, even those that are passed from the triggering "admin" job are available as environment variables (even if they are not explicitly defined in "non-admin" job)

Related

How to get Current logged in User in Jenkins?

I have setup a parametrized job to deploy on several environments. Now i want to restrict deployments to some environments based on the LDAP-groups of the current user.
I am using Dynamic Choice Scriptler for the above task but issue i am facing is that User.current() is returning value SYSTEM. Is there any way to find out the current user without triggering the build?

Is there a way in Jenkins to create a manual approval for a job to be approved by multiple approvers?

I have a promotion Job A which on successful build triggers email to certain recipients with Jenkins console link and build#. When the user clicks on the link from the email, he will login through his user id and clicks on approve, upon which Job B in the pipeline triggers. Now I want to achieve this for multiple approvers, meaning if Job A sent email to 3 users, Job B should not be triggered until all approvers approve. Seems like their is no option in promoted build plugin for the same. Any ideas, suggestions would be helpful.
May be this plugin can help you with the approvals.
Build Pipeline
This plugin provides a Build Pipeline View of upstream and downstream connected jobs that typically form a build pipeline. In addition, it offers the ability to define manual triggers for jobs that require intervention prior to execution, e.g. an approval process outside of Jenkins

Jenkins Pipeline (aka Workfow) security with nodes

I want to create a Groovy script using Pipeline plugin in Jenkins handling the security for only some users can enter to the node.
This would be the example:
node('master') {
//code..... more code
}
node('production') {
//more code.....
}
I want to be able that only some users can run succesful the production node without using the input step that ask for only specific users/groups can approve it.
Is there a configuration option where I can configure the security of a specific Node about what users (or group) can execute scripts on it.
Note: I am using only Jenkisn 1.6 (not Cloudbees which it is with more complex security options)
Edited 04/20/2016 reflecting discussions in comment:
Update: Goal: Preventing unauthorized user from executing jobs on a selection of Jenkins node.
Update: The Job Restrictions Plugin referred by luka5z would be a promising fit for the goal, when using it in conjunction with Role Strategy Plugin.
Give Matrix-based security a try with this plugin Role Strategy Plugin. First, you need to set users/anonymous group global role to have a very minimal access. Then you can set slave roles that only allow users to use node name in staring in a pattern e.g QA_Slave*, and only a small group, say admin, have all permissions on all slaves, which implies Production.
Update: Role Strategy Plugin can prevent user from modifying policy applied to node, but would not protect node from running a job it was tagged to. [unauthorized slave assignment in job configuration] where Job Restrictions Plugin would independently apply restrictions on the node level, without go extreme and taking all job configuration access away.

Jenkins - control who can trigger a build

Is there a way we can control which user can click "Build Now" in Jenkins? Basically we dont want all the users who are logged in Jenkins to trigger a build.
Also is this possible project-wise?
I am relatively new in configuring Jenkins, though I have used Jenkins more as an end user and not an admin, so would really appreciate any helpful inputs. I tried using this : https://wiki.jenkins-ci.org/display/JENKINS/Matrix-based+security and this https://wiki.jenkins-ci.org/display/JENKINS/Standard+Security+Setup, but for some reason its still allowing users to trigger a build.
You can also use RoleStrategyPlugin
This will be more helpful to manage large numbers of user using multiple projects.
The details to use and your doubt in the comment is addressed here
I am using Matrix Authorization Strategy Plugin, it offers matrix-based security authorization strategies, both global and per-project.
Global scope
http://jenkins_server/configureSecurity/--> Authorization-->Project-based Matrix Authorization Strategy
Project scope

How to block some Jobs for some user level in Jenkins?

I want a block some jobs for a user level for example I have 3 jobs:
Job1 (All the register user can execute this).
Job2 (Only some user can execute this)
Job3 (All the register user can execute this).
Set the Global Security (http://<your_server>/configureSecurity/?) to the configuration that matches most jobs (enable Job Build) and then enable Project-based security for the other jobs (via the jon configuration) and set up as required by disabling Job Build.
Enter the user name in User/group to add: and then configure as required. In this case I've limited control to two users
You need to use Project-based Matrix Authorization Strategy to achieve this. Hudson/Jenkin >> Manage Hudson >> Configre Security >> Authorization, and select Project-based Matrix Authorization Strategy. Now in the configuration page of each job you will have an option Enable job-based security. You can give access permissions for the users here.
This works for me : Role Strategy Plugin
But you need understand it and its official documentation is poor, so go to :
https://stackoverflow.com/a/38516162/3957754
The below link provides the clear guideline to grant/restrict the access to Jenkins Jobs.
http://www.kblearningacademy.com/configure-role-strategy-plugin-in-jenkins/
Its very useful & am able to do the same.

Resources