-
-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing assigning the STDOUT result of a task to a variable #178
Comments
Hi @dischello, Sorry, I'm not sure I understood the request. Do you want to assign the result of a task (STDOUT) to a variable? |
Hi @andreynering, Sorry for confusion. task-B:
vars:
ARG1:
ARG2:
task-A:
vars:
VAR-A:
- task task-B "ARG1=agr1" "ARG2=arg2" worked perfectly fine for me. |
@dischello Yeah, that's not ideal, but recursively calling I'll keep this open in order to maybe allow this in the future: vars:
FOO: {task: foobar} This can be tricky though, since it can in theory allow a recursive dependency (i.e. a var depending on a task and this task depending on the same variable). For now you can just use |
@andreynering I think this feature could be great but my use case would be a bit different. I think if the output of any generic command (or task) could be assigned to a variable within the scope (or perhaps global) it would greatly improve the flexibility and allow variables to be generated only after preconditions, something I cannot figure out how to do now. Here's an example of something I'm trying to transition from our own internal Go task runner. tasks:
install:
desc: Create a user with accounts
vars:
GIT_USER_EMAIL:
sh: git config user.email
EMAIL: "{{.EMAIL | default (.GIT_USER_EMAIL)}}"
cmds:
- kubectl rollout status deployment/app
- echo "Creating Accounts for {{.EMAIL}}"
- cmd: kubectl get po -lapp=app -o jsonpath='{.items[*].metadata.name}' | cut -d" " -f1
assign: POD
- kubectl exec -it {{.POD}} -c app -- bin/console dev:install {{.EMAIL}}
- task: prepare
vars: { POD_NAME: "{{.POD}}" }
- echo -e "\nSuccess! You can now login." The reason I find this important is that the As far as the original poster, I imagine creating a task to assign could also be helpful. tasks:
get-data:
cmds:
- echo "my data"
run:
cmds:
- task: get-data
assign: DATA
- 'echo "{{.DATA}}" | jq | etc' In this scenario there are considerations on what kind of output is expected with multiple commands and how to merge those together if necessary. Let me know what you think. If this is something you think we can add I'll be more than happy to make a PR. Thanks! |
@dolfelt where you able to get the I have been trying to get it working for something I am doing, and have bumped into an issue reading from Stdout. If you have would you be able to share your code please? |
I also have a case where assigning stdout of another command would help. This is the shell command: sudo docker run -d --publish 8043 --volume ${CREDS}:/srv/http \
--name secrets-server pierrezemb/gostatic
secrets_ip=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' secrets-server)
sudo docker build ... --add-host=secrets-server:${secrets_ip} ... Here, |
Something like this would be great! I'm currently looking for a way to have one cmd or task save output to env or var that can be referenced in the next cmd or task. Any news on this? |
Throwing this out there: would it make more sense to attack this problem from the opposite end? eg: tasks:
get-data:
cmds:
- echo "my data"
use-data:
vars:
DATA:
task: get-data
cmds:
- 'echo "{{.DATA}}" | jq | etc' this strategy would conflict with the any-variables experiment, but I think it's cleaner this way. |
another workaround I've been playing with using a scripts:
AUTO_SCALING_GROUP: &AUTO_SCALING_GROUP
sh: >-
aws autoscaling describe-auto-scaling-groups
| jq -r '.AutoScalingGroups[].AutoScalingGroupName'
| fzf --prompt '{{.PROMPT | default "Pick Auto Scaling Group > "}}'
tasks:
list-instances:
desc: List instance IDs in auto scaling group
vars:
PROMPT: "This overrides the prompt below > "
AUTO_SCALING_GROUP: *AUTO_SCALING_GROUP
cmds:
- >-
aws autoscaling describe-auto-scaling-groups
--auto-scaling-group-names {{.AUTO_SCALING_GROUP}}
| jq -r '.AutoScalingGroups[].Instances[].InstanceId |
I was coming here hoping to find something like this. Specifically I was hoping to find a way to get this to work:
|
Set value of the task to the var:
it would be nice to have such thing to reuse existing tasks more efficiently or is there way to pass variable/values/data between task?
The text was updated successfully, but these errors were encountered: