CCS-4 - Build change 9 #18
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: jira-evidence-example | |
| on: | |
| workflow_dispatch: # This allows manual triggering of the workflow | |
| push: | |
| branches: | |
| - carmit_examples | |
| pull_request: | |
| branches: | |
| - carmit_examples | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| docker-build-with-jira-evidence: | |
| runs-on: ubuntu-latest | |
| env: | |
| DOCKER_REPO: 'test-docker-local' | |
| IMAGE_NAME: 'my-very-cool-image:${{ github.run_number }}' | |
| BUILD_NAME: 'jira-evidence-example' | |
| steps: | |
| - name: Install jfrog cli | |
| id: setup-cli | |
| uses: jfrog/setup-jfrog-cli@v4 | |
| env: | |
| JF_URL: ${{ vars.ARTIFACTORY_URL }} | |
| with: | |
| oidc-provider-name: jfrog-github-oidc | |
| - uses: actions/checkout@v4 | |
| - name: Log in to Artifactory Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ vars.ARTIFACTORY_URL }} | |
| username: ${{ steps.setup-cli.outputs.oidc-user }} | |
| password: ${{ steps.setup-cli.outputs.oidc-token }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and Push Docker image | |
| uses: docker/build-push-action@v6 | |
| id: docker-build | |
| with: | |
| push: true | |
| provenance: false | |
| platforms: linux/amd64 #, linux/arm64 | |
| build-args: REPO_URL=${{ vars.JF_URL }}/example-project-docker-dev-remote | |
| tags: ${{ vars.JF_URL }}/${{ env.DOCKER_REPO }}/${{ env.IMAGE_NAME }} | |
| - name: add docker package to build | |
| run: | | |
| echo "${{ vars.JF_URL }}/${{ env.DOCKER_REPO }}/${{ env.IMAGE_NAME }}@${{ steps.docker-build.outputs.digest }}" > metadata.json | |
| jf rt build-docker-create ${{ env.DOCKER_REPO }} --image-file metadata.json --build-name ${{ env.BUILD_NAME }} --build-number ${{ github.run_number }} | |
| - name: Publish build info | |
| if: ${{ true }} | |
| run: | | |
| jf rt build-collect-env | |
| jf rt build-add-git | |
| jf rt build-publish | |
| - name: Get git commit messages | |
| env: | |
| jira_token: ${{ secrets.JIRA_TOKEN }} | |
| jira_username: ${{ secrets.JIRA_USERNAME }} | |
| jira_url: ${{ secrets.JIRA_URL }} | |
| run: | | |
| # Get the latest commit that triggered the build | |
| START_COMMIT=$(git rev-list --max-parents=0 HEAD) | |
| echo "START_COMMIT=$START_COMMIT" | |
| #git log --oneline "$START_COMMIT"..HEAD | |
| echo "git log --oneline" | |
| git log --oneline | |
| echo "git log -1 --format=%H %s" | |
| git log -1 --format="%H %s" | |
| START_COMMIT1=$(git log -1 --format="%H %s") | |
| echo "START_COMMIT1=$START_COMMIT1" | |
| second_element=$(echo "$START_COMMIT1" | cut -d' ' -f2) | |
| echo "$second_element" | |
| # Check if the second element matches the JIRA ID format | |
| if [[ $second_element =~ ^[A-Z]+-[0-9]+$ ]]; then | |
| echo "The second element is a valid JIRA ID: $second_element" | |
| ./examples/jira-transition-example/bin/jira-transition-checker-linux-amd64 aaa $second_element > predicate.json | |
| echo "---------predicate---------" | |
| cat predicate.json | |
| echo "----------------------------" | |
| # Attach evidence onto build using JFrog CLI | |
| jf evd create \ | |
| --build-name "${{ env.BUILD_NAME }}" \ | |
| --build-number "${{ github.run_number }}" \ | |
| --predicate ./predicate.json \ | |
| --predicate-type https://jfrog.com/evidence/build-jira-transition/v1 \ | |
| --key "${{ secrets.PRIVATE_KEY }}" \ | |
| --key-alias ${{ vars.JF_KEY_ALIAS }} | |
| else | |
| echo "The second element is not a valid JIRA ID" | |
| fi |