How to upload travis artifacts to S3 only in develop branch - git-branch

I've read this blog post that explains how to configure travis to upload build artifacts to S3. How do I limit the "travis-artifacts upload" command to work only in the "develop" branch? I still want the branches to run CI, I just don't want them to overwrite the build artifacts uploaded by the develop branch.

You can extend the command to check for the branch name:
after_success:
- test ${TRAVIS_BRANCH} = develop && travis-artifacts upload

Related

Do I need to upload build folder to branch in order to make upload-artifact CI/CD work?

I have been working on two separate branches
trunk
distribute
CI/CD pipelines are setup on distribute branch. When push is made to distribute branch, CI/CD workflow triggers and do the jobs listed in the main.yml file.
Here it is:
name: Build & upload to Firebase App Distribution
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
# This will checkout the current repo
- name: Checkout
uses: actions/checkout#v2.4.2
# This will upload artifact (.apk) from your workflow
- uses: actions/upload-artifact#v3
with:
name: release-apk
path: build/app/outputs/flutter-apk/app-release.apk
# Distribute to Testers using Firebase App Distribution service
- name: Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action#v1.3.3
with:
appId: ${{secrets.FIREBASE_APP_ID}}
token: ${{secrets.FIREBASE_TOKEN}
groups: Testers
file: build/app/outputs/flutter-apk/app-release.apk
We have added /build/ in .gitignore so build folder won't be pushed to distribute branch. The only thing it contains is the .github/workflow/main.yml that will trigger the CI/CD workflow.
Now the questions is,
Do I need to remove /build/ from .gitignore so my build folder will also be pushed to distribute branch where upload-artifact can pick the file from build/app/outputs/flutter-apk/app-release.apk declared in main.yml file?
Another question; Where does upload-artifact picks the file? Whether it picks from the current branch (in my case; build folder is not present there)? Or it picks from the current local project directory? (in my case; build folder is present)
This thing is confusing me too much :(
Thanks.
Here is the error:

Errors on using git commands in Azure pipelines

I am working on an Azure pipeline for a dotnet core project that runs on Windows Self hosted agent.
I want my pipeline to use Git commands to check out the release branch and merge the develop branch into it. Next steps will be to build the release branch and deploy to intranet servers
I don’t know Git wording very good, I was using TFS for years. I use the commands below and got the logs here:
- task: CmdLine#2
displayName: Checkout Release branch
inputs:
script: |
#echo off
git checkout release
git pull develop
git status
From the logs, I understand:
It downloads the content of the develop branch because it is the default branch in GitHub, I’d rather want the release branch but I believe Azure is like that
I manage to switch to release but I have these errors that I don’t understand:
##[error]Previous HEAD position was bc94bd2 Update Staging Build Pipeline.yml
##[error]Switched to branch 'release'
I understood that pull can be used with local or remote branch so I use it to fetch and merge the develop branch to the release branch but I get: [error]fatal: 'develop' does not appear to be a git repository
Do I have to specify credentials on every calls to git?
On the last step, it fetches again the code from the develop branch and I understand why
If you could help me improve my script, that would be great,
Many thanks.
You can use git merge commands to merge branches. To merge develop branch into release branch you can use git merge origin/develop. Check the document for more information. See below example:
steps:
- checkout: self
persistCredentials: true
- task: cmdLine#2
inputs:
script: |
#echo off
git checkout release
git merge origin/develop
git status
However, it is not recommended to deploy release branch in above way. You can change the default branch of your azure pipeline to release branch and enabled the Continuous Integration trigger for release branch.
So that you can create a pull request to merge develop into release from the github UI or by using commands. After develop is merged into release, the azure pipeline will be automatically triggered to deploy from release branch. Note: the azure pipeline yaml file must exist in release branch too. See below steps:
1, To change azure pipeline branch from develop to release:
On your azure devops pipeline Edit page, Click the 3dots and click Triggers
Go to YAML tab--> Get Sources-->Click the 3dots to change the default branch.
2, Set CI trigger for release branch
In the azure pipeline yaml file, set the trigger to include release branch(You can also set PR trigger):
(Actually you do not need to follow above steps to change the default branch. You just need to include the azure pipeline yaml file in release branch and set the CI trigger to include release branch as below)
trigger:
branches:
include:
- release
exclude:
- develop #if you want disable CI trigger for develop branch
By adding the CI trigger to include the release branch in the azure pipeline yaml file. Azure pipeline will automatically be triggered on release branch when merging from develop into release branch.

Merge GitHub branches from Azure

I am setting up CI/CD at work and there is one step I’m not sure how to do and furthermore, if it is a right thing do.
For background, I am used to develop in C# with Visual Studio, source code in TFS and deploying with basic script that copies files on the intranet.
Now, I’m requested to setup Build and Release pipelines on Dot Net Core projects in GitHub.
I have three branches on this project: DEV, RELEASE and MASTER
I created one pipeline that triggers on DEV’s commits, creates an artefact and deploy to DEV server.
Those are the pipelines that deploy all developers work to a DEV server where they run their own tests.
Next step, when we want to deploy to staging servers, we click a button in Azure, this merge the DEV branch to the RELEASE branch but I know close to nothing in GitHub, not even sure those are the appropriate words.
When the merge is done, this will trigger a build pipeline that will create a different artefact, when this artefact is updated, deploy to staging server.
Once this release is validated on Staging and Quality, we would merge RELEASE to MASTER and do the same until PROD servers. It is all on intranet and self-hosted agents.
Is that a good way of doing things? Can it be done this way? I need a PowerShell task or is there something that exists?
If you are using Azure DevOps pipeline, the pipeline should select GitHub for repository type, then we can configure the CI trigger.
a. Configure CI trigger:
Classic steps:
1.Open project setting->Service connections->select GitHub-> create a new GitHub service connection
2.Create a new build pipeline via classic editor-> Select GitHub as the source.
3.Open pipeline->select the tab Triggers-> enable the option Enable continuous integration and configure the Branch filters
b.YAML steps:
1.Open project setting->Service connections->select GitHub-> create a new GitHub service connection
2.Create a new build pipeline and select GitHub(YAML)
c.The sample of Check out GitHub repositories in your pipeline
resources:
repositories:
- repository: MyGitHubRepo # The name used to reference this repository in the checkout step
type: github
endpoint: MyGitHubServiceConnection
name: MyGitHubOrgOrUser/MyGitHubRepo
trigger:
- {branch name}
Configure CD trigger:
Please refer to this doc to configure the release trigger.
If you are using GitHub action.
Please select the correct workflow to configure the CI/CD, Please refer this doc for more details
CI sample:
on:
push:
branches:
- ' DEV'
Update1
When Dev branch is updated, it is built and deployed to Dev server by pipeline.
Create build A and release B, configure the CI build trigger, when the branch Dev is updated, it triggers the build pipeline A, and when build pipeline A is completed, it triggers the release pipeline B.
click a button to synchronize Dev branch to Release branch.
We cannot see the button, as a workaround, we can add task powershell and call the API to create pull request and complete the pull request. We also can add task cmd and publish the code via git cmd

Add TFS Build status to github

I've user Azure portal to setup continuous integration for my Web App. Sources are hosted on GitHub.
When I click GitHub project->Code->Branches, I see build status for master branch:
All very nice untill now. However, I've manually setup CI build on dev branch in VSTS, but it is not shown in github.
How do I report build status back to github, so I will see it on dev branch as well?
From the piture you posted above, you have pushed 7 commits for master branch, no commits for dev branch. Now you set up a CI build in VSTS to build your project in dev branch. Make sure that Trigger path has set to dev branch correctly in your build definition. Then you push a commit for dev branch, this build definition will be triggered and you will see the build symbol in GitHub.
In addition, the symbol appears only for CI build, if you manually trigger the build VSTS, it doesn't show.
Build definition trigger:
Build definition repository setting:

Run Coverity scan for every Travis pull request build

I want to automate student assignment grading system as much as possible. Ideally these steps will be taken when submitting the assignment.
Student forks my Github repository and modifies files
Student pushes the local code to his repository and creates pull request
Travis CI detects pull request and run Pull Request build
If code builds successfully, Coverity runs static code analysis for the pull request
Student gets build status from the Github pull request page
I've successfully set Travis builds for every pull request in my repo. I have successfully run Coverity scan via Travis for every commit on my repo. But I can't trigger Coverity scans for pull request, only Travis builds are run. Can I fix this problem and maintain Coverity scan report for every pull request?
This is my .travis.yml
language: c
compiler: gcc
env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "WHkT1bLbpz8VA8tl+qyZvWHLg7YvnMPhCNXCEAQQaklcDq8HQ7glIrrs35VnTDfs09tVgkPbgsAfwBuwxqkmmxWaquW0AHdb6cefNpQVj2ovUriQVNBFmjfte9Bbq0NWKoLp+4IY/3IDfLoUOekOIDXuQtkJhNvX1zkkt21lSeo="
addons:
coverity_scan:
project:
name: "Freeuni-CN101-2014/midterm"
description: "Build submitted via Travis CI"
notification_email: example#mail.com
build_command_prepend: ""
build_command: "make"
branch_pattern: "*"
script: make
Travis output of pull request here
Travis output after I merged the pull request with the main branch here
I asked Coverity support and they replied
The trigger for Coverity Scan happens for the specific branch and not
for the pull request, and specially the branch that is mentioned in
.travis.yml
UPDATE
With user #Admaster's help I started playing with Jenkins and cppcheck plugin. Jenkins is scanning pull requests successfully without setting build status to Github commits(Travis does set).
Example
So I continued experimenting with Travis and came over this repo. I changed my .travis.yml file that looks like this
language: c
compiler: gcc
before_install:
- sudo apt-get install -qq cppcheck
script:
- cppcheck --error-exitcode=1 --quiet .
- make
cppcheck may be less effective then Coverity, but it's sufficient for students' assignments.
I suggest not using Coverity, because free account has a lots of limits.
Better is to use Jenkins.
I will try to make configuration espacially for You.
Jenkins support pull requests on github