I have tried the following to get a commit sha of a specific build.
But Jenkins showed a security error. Is there a possible way to achieve this?
import hudson.model.*
def jenkins_job_name = "Some Job"
def build_number = 46
def jenkins_job = Hudson.instance.getItem(jenkins_job_name)
def getBuild = jenkins_job.getBuildByNumber(build_number)
def commit_sha = getBuild.getEnvironment().get('GIT_COMMIT')
*Scripts not permitted to use method hudson.model.Run getEnvironment. Administrators can decide whether to approve or reject this signature.*
Asked
Active
Viewed 304 times
0

Abhinay Reddy Keesara
- 9,763
- 2
- 18
- 28
-
1Did you try approving it from Jenkins UI `Manage Jenkins -> In-process Script Approval` – Pamela Sarkisyan Feb 10 '22 at 10:25
-
no luck .. post script approval .. got null as response – Abhinay Reddy Keesara Feb 10 '22 at 20:17