I'm new to Azure DevOps, and I was wondering if there was a way to automatically detected a .yml build file and create a pipeline without having to interact with the site.
I have tried creating a file called azure-pipelines.yml in the root of the repo, with no luck.
Is there anyway to automatically create pipelines? Like how Jenkins detects a Jenkinsfile?
No this is nott possible out of the box, because YAML file is not always pipeline definition. You my try to figure out if it is trully is, however you need to listen for repo changes and in fact you can do this via another pipeline ;) for instance as this:
check if commit has a new yaml file added
verify if the file is pipeline
create a pipeline using azure cli (for instance)
However, this would be quite a lot of work and then you need to create such pipeline in every repo you want to have this detection enabled.
Related
I use github for hosting my projects and have multiple projects in github. And I use Azure devops for CICD alone. I have a single project in Azure devops, where I create individual pipeline corresponding to each project in my github repo. All these github projects would need to use the same azure-pipeline.yml for build. So instead of keeping the same yml file in each project, is there a way I can keep this yml centrally. So that in future, if at all a change is required, I need not do it for all individual projects, instead, update the main yml template.
A single yml file where I have all the code is even possible for my usecase? Any help is much appreciated
Have you considered using templates? Essentially you have would end up with a single template containing the main build steps that is reusable and individual yaml for each pipeline that can pass parameters to the template for any differences you have between them (such as different triggers or variable values). This way you can update all pipelines by making changes to the template
Template documentation
According to your description, you may setup a repo contains all the YAML files for pipelines. Kindly also be advised that we can also keep the templates in other repositories, if we have defined the repository resources in the core YAML pipeline. Kindly refer to the sample Core and template YAML files below.
#Core YAML in Azure Repos
trigger: none
pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: GitHub_REPO_1
type: github
name: GitHubAccountName/GitHubRepo1
endpoint: GitHubServiceConnectionName
- repository: GitHub_REPO_2
type: github
name: GitHubAccountName/GitHubRepo2
endpoint: GitHubServiceConnectionName
steps:
- checkout: none
# - checkout: GitHub_REPO_1
- template: GHREPO1.yml#GitHub_REPO_1
# - checkout: GitHub_REPO_2
- template: GHREPO2.yml#GitHub_REPO_2
#Template YAML from GitHub Repo
steps:
- script: echo "This YAML template is from GitHubRepo1"
displayName: 'Template From GitHubRepo1'
By the way, we could also checkout the code from one or multiple repository resource(s) and trigger the pipeline by the commits from the repository resources. Please refer to the following documents for more information.
Define YAML resources for Azure Pipelines - Azure Pipelines | Microsoft Docs
Check out multiple repositories in your pipeline - Azure Pipelines | Microsoft Docs
I want to create Azure DevOps pipelines, but instead of writing new yaml files, use prepared ones that are in a github repository.
I have connected GitHub to my Azure DevOps account, but I Can't see an option to use yaml files in that repository.
I only have an option to create a new pipeline yaml, and then set it in the repo folder structure.
If I try and set it on the location of the yaml file I want to use, which is already in the repo, I get - of course, an error stating there's a file there.
My work around is to set a new yaml file with a different name, copy the content from the existing file and then delete that one and rename the new file to the name of the file I copied from.
Surely there must be a better, easier, more logical and short way.
I would appreciate any help.
Under project settings you should link your Github account.
Then you can go and create a new pipeline and select the Github location
after this step, your available github repositories will appear and you can select your existing .YML file.
Existing pipeline:
We have an open source project in GitHub. And we use Azure DevOps pipelines for our CI.
We publish our artefacts to S3 and Maven after successful tests, so all the credentials are stored as secret variables.
It's nice that export and echo $top_secret are conveniently obfuscated with ***, but unfortunately literally any user on GitHub can create a pull request against our repo, and as part of the changes, they can edit our azure-pipelines.yml and call a curl (or similar) to read the credentials from environmental variables and send them to their own server.
In other CI providers (Travis CI) secret variables are not accessible from PR branches.
How can I prevent PRs from touching my CI configuration file and do anything with it?
How can I prevent PRs from touching my CI configuration file and do anything with it?
You CI configuration file is save in the GitHub open source and you want to restrict users from changing this file, right? Since we cannot set file permission in the GitHub. we cannot prevent PRs from touching your CI configuration file.
As a workaround, we could create classic editor pipeline in the Azure DevOps and set the CI Trigger, such as below. If users do not have permission to change the build definition, they cannot change your CI build definition.
Update1
I am currently planning on a type of multi-tenant system, were different resource groups with a set of AppServices are deployed for customers via ARM Templates. Hence, each customer has its own Resource Group and set of AppServices. Currently we use Azure DevOps to deploy to a set of AppServices used for Development and Quality Assurance before it gets to Production. I am now trying to incorporate DevOps into the mix, automating a pipeline creation of some sort... (it would be a copy of an existing pipeline but only changing the Target AppServices). Which is were my question comes from, Is there a way to dynamically create or edit a Release pipeline to add the deployment of those new AppServices, without the need of manually edit or create a pipeline an adding those newly created AppServices, I was thinking something around the lines of being able to copy a yaml file template then replacing the necessary info to point to those AppServices after they have been created, but I am not totally sure where could I store the new yaml file so that it is picked up by Azure DevOps, or how could I would accomplish these, with the main idea being that all of this continues to be part of an automated process (if possible).
Thanks a lot for any help, any suggestion is appreciated.
EDIT:
The question is not about how to Deploy an ARM Template through the DevOps release pipeline (I plan on using a PowerShell Script/REST API to accomplish that), instead, is about when the AppServices Resources are created, I need to deploy code to those newly created AppServices and also update that code when necessary (Hopefully through a Release Pipeline), somehow generate a new release pipeline each time I deploy a new set of Resources. So that, when there is a new update, I could easily have that pipeline triggered and that set if AppServices can be updated (created as part of the automation process "dynamically"). (I Already have a similar pipeline that deploys to a "static" set of AppServices).
This is possible as you eluded to with YAML Pipelines. Based upon the scenario you have subscribed each repository would have it's own pipeline.yml file that will define the trigger, pool etc. It would also reference a repository that will house your yaml template.
The template would accept whichever parameters you may required (resource group, app service name, etc...) The triggering pipeline associated with each repository would pass this information leveraging the teamplate.
By doing this CI/CD can be set up to trigger on the individual pipelines and deploy the appropriate code all while leveraging the same YAML template.
The repository reference would be similar to:
resources:
repositories:
- repository: YAMLTemplates
type: git
name: OrginazationName/YAML Project Name
With the call to the template being similar to:
- template: azure-ARM-template.yml#YAMLTemplate
parameters:
appServiceName: 'AppServiceName'
resourceGroupName: 'ResourceGroupName'
UPDATE
At a high level the YAML pipeline would consist of the following. If all App Services are similar as stated and ARM Templates are similar this how it could be constructed and triggered based on a folder path:
Build necessary artifacts
Publish Pipeline
Deploy Azure Resource Group Task
Deploy App Settings Task (if applicable)
Deploy App Service
Release the deployment pieces for each environment in appropriate stages to help alleviate the amount of copying and pasting each of the above tasks can be part of a template either individually at a task, combination of tasks, or all in one. This would allow for defining the YAML once and referencing it and including app specific components as needed as parameters to the templates.
I have a Azure DevOps pipeline that automates user creation in salesforce. I am expecting the user details in an excel file, which is to be fed to the Azure DevOps pipeline as a pre-build parameter. However, I am not able to find a solution to it in Azure DevOps.
I had implemented this in Jenkins already using File parameter plugin in my previous projects. Does Azure DevOps has this capability?
After searching through various blogs and posts, I realized that there is no way to get this done directly in VSTS. However, I was able to get a work around for the same.
I created a VSTS User story and uploaded my attachment there
Using the Work Item ID, I used the work Item api to get the attachment ID.
Using the attachment API I was able to write a python script to download this attachment as a part of a pre-step in the Pipeline. Then this was available to use through out my automation script.
I don't think you can load a file before the build start and read the variables, but, you can add a task that read the variables from a file and put him in the beginning (the first step in your pipeline).
There are few extensions to read variable from a JSON file, for example: Json to Variable.
If you want to read from excel I think you should write a script that does it.
Using local hosted agent, you can publish artifact from local share, then move to i.e. ms-hosted agent and use it normally.
- task: DownloadFileshareArtifacts#1
inputs:
filesharePath: '\\myhost\myshare\myfolder'
artifactName: 'my-artifact'
downloadPath: '$(System.ArtifactsDirectory)'
parallelizationLimit: '8'
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/download-fileshare-artifacts?view=azure-devops