I'm trying to deploy an authProvider configuration that uses a custom class, and apparently in order to do that the metadata requires a valid running user as part of the configuration in order to deploy. I sort of have a solution cooked up to do it dynamically, but I think its lame so wondering what other ideas there might be.
I've managed to sort out a different but similar 'config' generation by creating a template, then I have a CCI task that runs a shell command to copy the file to the destination directory. Then another CCI task that does a find/replace on the copied template file and populates it with the value of an environment variable. The trick in the authprovider case is I have to poll the target/default org for this info before I can use it in the configuration.
My Python manna is pretty low admittedly, instead I created a shell script that manages to get the running user of the default org and then just does all of the other copy & find/replace options. I thought I could craft a shell command that would set an environment variable as a CCI task, but I cannot for the life of me sort out how to grab it.
If I run this on the command line it works fine.
export AUTH_USER=$(sfdx force:user:display --json | echo '<executionUser>'$(jq .result.username -r)'</executionUser>')
...but trying to do that as a shell command in CCI doesn't seem to do anything near as I can tell, no errors either, so I'm assuming the command failing quietly. *jq* is a JSON parser a colleague suggested. https://formulae.brew.sh/formula/jq
I can't help but think the current org user is somehow stored locally, but I've not been able to locate it. Even then I'm wondering if I'd run into a similar issue trying to set an environment variable on the fly.
This is quite easy to accomplish using a tiny bit of Python to extend the built in FindReplace utility task class shipped with CumulusCI. You can do it yourself with these steps: 1. Create the file tasks/util.py in the root of your project
from cumulusci.tasks.util import FindReplace as FindReplace
class FindReplaceUsername(FindReplace):
def _init_options(self, kwargs):
# Run the _init_options logic from FindReplace
super()._init_options(kwargs)
# Set the replace option to the org's username
self.options["replace"] = self.org_config.username
2. Add a task to your cumulusci.yml file
tasks:
find_replace_username:
description: Replaces a string with the target org username
class_path: tasks.util.FindReplaceUsername
options:
find: INSERTUSERNAMEHERE
path: some/directory
file_pattern: somefile.txt
copy_file:
class_path: cumulusci.tasks.util.CopyFile
options:
src: some/path/to/source.txt
dest: output/file.txt
3. Add a flow that copies a file and replaces the string with the target org's username
flows:
find_replace_username:
steps:
1:
task: copy_file
options:
dest: somefile.txt
2:
task: find_replace_username
At that point, you should be able to inspect the flow:
cci flow info find_replace_username
And run it:
cci flow run find_replace_username