May I ask why you need this information in the build / during the build instead of via e.g. the API? I’d imagine for auditing an API option would be better than an env var during the build
@viktorbenei Exactly wat @bernat says! My primary use case is showing it in slack messages, and secondary use case is to have it available in build logs.
Bumping this. I also have Slack notifications as my primary use case, but this could be generally-useful, as I proposed to @fehersanyi-bitrise:
The feature I’m requesting is simply an environment variable that is present when someone manually triggers a build, which includes information about the Bitrise user that triggered it
This can then be used in workflow scripts, for example: a BITRISE_TRIGGER_SOURCE environment variable that could be “0” for “Webhook”-triggered builds, “1” for “Scheduled”, maybe “3” for manually-launched workflows, etc.
In the manual case, Bitrise could also provide other env vars, e.g. BITRISE_TRIGGER_USER, BITRISE_TRIGGER_EMAIL, etc., which would respectively include the username, email address, etc. of the user who launched the workflow.
Beyond notification routing, this information could also be used as input to build steps that might generate custom artifacts, apps, etc.
+1 though I’d go further and make a Slack app that would allow to invoke Bitrise builds through API, then this info will be available in build parameters or environments (haven’t checked how Bitrise API approaches that but I suppose it would be something like that)
+1 bump. Any updates on this? We would also like the name and email of the person who triggered the Bitrise build exposed to env vars. so we can show it in the slack message like the others previously said.
I will see if we can get these values exposed for manually started builds.
For Webhook Triggered builds you can get these values from the Environment Variables
|$GIT_CLONE_COMMIT_AUTHOR_NAME|The name of the author of the cloned commit.|
|$GIT_CLONE_COMMIT_AUTHOR_EMAIL|The email of the author of the cloned commit.|
|$GIT_CLONE_COMMIT_COMMITER_NAME|The name of the committer of the cloned commit.|
|$GIT_CLONE_COMMIT_COMMITER_EMAIL|The email of the committer of the cloned commit.|
Here’s a bit of YAML to achieve the same using the Bitrise API in a pipeline. It’s certainly not as easy as an env var would be, but if you need it before an env var is (maybe) made available this can help
- script@1:
title: Check for manual trigger
inputs:
- runner_bin: ruby
- content: |-
require "faraday"
nightly_pl_params = {
'workflow' => 'nightly',
'branch' => ENV['BITRISE_GIT_BRANCH']
}
auth = {
'Authorization' => ENV["BITRISE_ACCESS_TOKEN"]
}
conn = Faraday.new(
url: "https://api.bitrise.io/v0.1/apps/#{ENV['BITRISE_APP_SLUG']}/",
headers: auth
) do |f|
f.request :json
f.response :json
end
# Gets the list of nightly builds for the branch
nightly_pl_builds = conn.get('builds', params=nightly_pl_params)
if nightly_pl_builds.body['data'].length > 0
triggered_by = nightly_pl_builds.body['data'][0]['triggered_by']
puts "triggered_by: #{triggered_by}" # will be "manual-username" if manually triggered, "schedule" if scheduled etc.
if triggered_by.start_with?("manual-")
puts "Manual run detected
else
puts "Non-manual trigger detected
end
end