Q: Setting git committer's name to environment variable in Jenkins declarative pipeline In jenkins declarative pipeline, I am trying to get the name of git committer and then set it to en environment variable. Getting part works fine, however, no matter which syntax I tried, it doesn't work.
For example I tried script block:
script {
    env.GIT_CULPRIT = sh('git log --format="%ae" | head -1 | awk -F"@" \'{print $1}\'')
    echo "culprit: ${env.GIT_CULPRIT}"
}

Output:

[Pipeline] echo
  culprit: null

Tried environment block (inside dir block):
environment {
    env.GIT_CULPRIT = sh(script: 'git log --format="%ae" | head -1', returnStdout: true)
    echo "culprit: ${env.GIT_CULPRIT}"
}

Output:

WorkflowScript: 33: Missing required parameter: "name" @ line 33, column 21.
                         environment {
                         ^
WorkflowScript: 33: Missing required parameter: "value" @ line 33, column 21.
                         environment {
                         ^


A: From "Jenkins Pipeline - set and use environment variables", the second approach should work.
Except:

The above only works when the environment section is inside a "stage" but would yield "null" for WORKSPACE outside the stages.

Note that in the step section, that environment variable is referenced as ${VAR}, not ${env.VAR}
