git - I have an API which updates yaml file. I need to periodically update a yaml file which is deployed in a pipeline - TagMerge
4I have an API which updates yaml file. I need to periodically update a yaml file which is deployed in a pipelineI have an API which updates yaml file. I need to periodically update a yaml file which is deployed in a pipeline

I have an API which updates yaml file. I need to periodically update a yaml file which is deployed in a pipeline

Asked 11 months ago
1
4 answers

If you are hosting the yaml file on GitHub, I'd suggest looking at GitHub Workflows. You can set GitHub actions to (next to respond to events) run on a schedule (see here). Then, the workflow has access to that repository (your package), can make API calls and push back changes. Something like this:

NOTE: I did not test this workflow

name: Trigger API update

on:
  schedule:
    - cron:  "0 6 * * *" # run everyday at six

jobs:
  ping_api_and_update:
    runs-on: ubuntu-latest
    steps:

    - uses: actions/checkout@v2
      with:
        ref: ${{ github.head_ref }}

    - name: Webhook
      uses: distributhor/workflow-webhook@v2
      env:
        webhook_url: ${{ secrets.API_URL }}
        webhook_secret: ${{ secrets.API_SECRET }}

    - name: do something with output
      run: |
        command based on API result
        maybe another command
        edit the yaml file in this repo
      shell: bash 

    - name: Commit changes
      uses: stefanzweifel/git-auto-commit-action@v4
      id: commit
      with:
        commit_message: Auto-update YAML
        commit_author: CI/CD <actions@github.com>
        

Alternatively, most (e.g. linux) servers can handle cron-jobs. You could let that cron-job trigger a script to handle all the steps. If you want to update a git repository then, you could use git on your server, and the specific repository as a git submodule. The script could then push the changes to the submodule to its respective repository.

As with most things, if it is private, you'll need to handle authentication and all that.

Source: link

0

NOTE: I did not test this workflow
name: Trigger API update

on:
  schedule:
    - cron:  "0 6 * * *" # run everyday at six

jobs:
  ping_api_and_update:
    runs-on: ubuntu-latest
    steps:

    - uses: actions/[email protected]
      with:
        ref: ${{ github.head_ref }}

    - name: Webhook
      uses: distributhor/[email protected]
      env:
        webhook_url: ${{ secrets.API_URL }}
        webhook_secret: ${{ secrets.API_SECRET }}

    - name: do something with output
      run: |
        command based on API result
        maybe another command
        edit the yaml file in this repo
      shell: bash 

    - name: Commit changes
      uses: stefanzweifel/[email protected]
      id: commit
      with:
        commit_message: Auto-update YAML
        commit_author: CI/CD <[email protected]>

Source: link

0

stages:
 - stage: Build
   jobs:
   - job: Build
- stage: Deploy
   jobs:
   - job: Deploy
     pool:
       vmImage: 'vs2017-win2016'
     steps:
artifactName: 'drop'

Source: link

0

The Azure DevOps build and release pipeline YAML has a section called ‘variables’ that lets you set — uhhh — variable values. What’s not obvious is that this is setting up environment variables for your pipeline execution. Here’s a sample pipeline.
trigger:
- main

pool:
  # vmImage: 'windows-latest'
  vmImage: 'ubuntu-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  ASPNETCORE_ENVIRONMENT: 'Production'

steps:
- task: NuGetToolInstaller@1

- script: set
  displayName: show all env vars

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

Source: link

Recent Questions on git

    Programming Languages