Automate Native Git with CI/CD

View as Markdown

Rather than pushing and pulling changes manually, automate the synchronization process using the Postman CLI push command within a CI/CD pipeline, triggered by events like merging a pull request.

Add a GitHub workflow to publish to Postman Cloud

  1. Set up your CI/CD Secret. To generate an API Key, create a Postman API key from your Postman account settings. Add this key as a protected secret (for example, POSTMAN_API_KEY) in your repository’s settings (for example, GitHub Secrets, GitLab Variables).

  2. Add the synchronization step to your pipeline. The primary command recommended for this workflow is postman workspace push. This command validates and synchronizes your local files with the cloud workspace.

Example: GitHub Actions workflow

Create or update your .github/workflows/postman-publish.yml file with the following steps:

1name: Publish changes to Postman
2on:
3 push:
4 branches:
5 - main # Trigger sync when code is merged to main
6
7jobs:
8 publish-changes:
9 runs-on: ubuntu-latest
10 steps:
11 - name: Checkout repository
12 uses: actions/checkout@v4
13
14 - name: Install Postman CLI
15 run: |
16 curl -o- "https://dl-cli.pstmn.io/install/unix.sh" | sh
17
18 - name: Verify Postman CLI version
19 run: postman --version
20 - name: Login to Postman
21 run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }}
22 - name: Publish changes to Cloud
23 run: postman workspace push -y
  • Use the --yes flag: In a CI/CD environment, use the -y or --yes option to skip manual confirmation prompts.

  • Validation: The push command automatically performs a “prepare” step to validate your files before syncing. You can skip this with --no-prepare if needed, though it’s not recommended for production pipelines.

Merge and validate your integration

To complete your setup, do the following:

  1. Commit the Postman files + GitHub workflow and push your branch.
  2. Create a PR to develop and merge it.
  3. Trigger a release to main.