How to trigger workflow from job on behalf of the job?

Hi. I want to trigger workflow (with parameters) from circleci job. Workflow and job is located in the same repository and same config.yml file. As per documentation I need to pass token for authetication. I tried to use my Personal API Token and pass it via CIRCLE_API_TOKEN variable and this works. But this approach is not good for me because:

  • all workflows triggered by job from ANY branch will show me as author

  • In case I will be deleted from (private) repo all such invocations will be failed (until CIRCLE_API_TOKEN will be updated to token of other ‘lucky’ user)

  • I’ll see all such triggered pipelines with workflows (which will be triggered by all jobs from all commiters) under “My Pilelines” filter.

         curl -u ${CIRCLE_API_TOKEN}: -X POST --header "Content-Type: application/json" -d '{
           "branch": "'$CIRCLE_BRANCH'",
           "parameters": { ... }
         }' https://circleci.com/api/v2/project/bb/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pipeline
    

So I have next question:
Can I trigger workflow from job on behalf of user which triggered this job? Or on behalf on circleci or any other service/user but not my own. By using credentials/token/whatever of current “session”. Maybe we have some hidden environment var with token for current session which can be passed to api call to trigger workflow?
I know that I can create ‘fake’ user but I think it is not the valid way.
P.S. I’m not organization admin of repository/circleci project

Any update on this? I’m facing the exact same issue.

1 Like