Joel
Joel

Reputation: 8948

Update property of specific item in array using yq 4

I'm using yq 4.3.1 to update the version field in this yaml:

jobs:
  my-job:
    steps:
      - name: Step 1
        id: step1
        uses: actions/step1
      - name: Step 2
        id: step2
        uses: actions/step2
        with:
          version: 1.2.3

But I can't figure out how to select the array item based on the id == 'step2' property so that I can update the version?

Upvotes: 0

Views: 2101

Answers (1)

Joel
Joel

Reputation: 8948

Why is it you always figure out the answer the second after you post a question on stackoverflow?

yq eval '(.jobs.my-job.steps[] | select(has("id")) | select(.id == "step2")).with.version = "1.2.4"' -i my.yaml

EDIT Wow, how wrong was I... :D Updated with a working version

Upvotes: 4

Related Questions