The current setup is as below
Version Control - Git
Repos and Branch hosted on - Azure DevOps
Codebase - External server
The dev team clones Azure Repo into local git project and any staged changes are committed via Git and pushed to specific branch of Azure DevOps. In this setup we would want to upload the changes to external FTP servers and avoid manual upload. Currently trying to use Azure Devops FTP Upload Task (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/ftp-upload?view=azure-devops), however facing issues; yaml script as below
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
phpVersion: 7.4
webAppName: 'Test Project'
buildConfiguration: 'Release'
vmImageName: 'ubuntu-latest'
steps:
- publish: $(System.DefaultWorkingDirectory)/AzureRepoName
artifact: Test Project Deploy
- task: FtpUpload#2
displayName: 'FTP Upload'
inputs:
credentialsOption: inputs
serverUrl: 'ftps://00.00.00.00:22'
username: ftp-username
password: ftp-password
rootDirectory: '$(System.DefaultWorkingDirectory)/AzureRepoName'
remoteDirectory: '/home/public_html'
clean: false
cleanContents: false
preservePaths: true
trustSSL: true
PROBLEM
Following errors occur when I commit (for test purposes) something.
Starting: PublishPipelineArtifact
==============================================================================
Task : Publish Pipeline Artifacts
Description : Publish (upload) a file or directory as a named artifact for the current run
Version : 1.199.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/publish-pipeline-artifact
==============================================================================
Artifact name input: Test Project Deploy
##[error]Path does not exist: /home/vsts/work/1/s/AzureRepoName
Finishing: PublishPipelineArtifact
I want to upload any staged change that is committed to main branch on Azure Devops to be automatically deploy on the remote FTP server
Thanks
On checkout devops agent will create /home/vsts/work/1/s/AzureRepoName folder with your source but actually when the checkout happens the /home/vsts/work/1/s folder is the repository root i.e. there is no AzureRepoName folder in there. so what you need is to publish /home/vsts/work/1/s folder itself as the artifact. also your ftp upload task should use rootDirectory: '$(System.DefaultWorkingDirectory)/AzureRepoName'
Related
Azure static web apps(preview) currently only works with a github account, and as a company policy we have to use Azure for repos and everything else (pipelines, releases, etc..) We are going to use the static web app just for viewing a simple angular website however all the source code must remain in the azure devops repo.
Is is possible to create a private github account and upload to it only the compiled angular files to make use of the static web app? for example we already have a pipeline to compile and deploy the angular website to an Azure web app service, can this pipeline be modified to publish the same files to the github account? and if so how?
You can do it in Azure Devops. Try put this YML in Azure DevOps Pipeline
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
name: 'yourApplicationName'
steps:
- task: NodeTool#0
inputs:
versionSpec: '12.x'
displayName: 'Install Node.js'
- script: |
npm install -g #angular/cli
npm install
displayName: 'npm install'
workingDirectory: '$(Build.SourcesDirectory)/yourApplicationName'
- task: AzureStaticWebApp#0
inputs:
app_location: "/yourApplicationName"
api_location: "api"
app_build_command: $(build_command)
output_location: "dist/yourApplicationName"
env:
azure_static_web_apps_api_token: $(deployment_token)
You can put build_command and deployment_token in the variables
Azure SWA is only available for code in Github at the moment.
However, you can get something pretty close with Azure App Service. Microsoft even has a couple blog posts about how to configure Azure App Service, Azure Repos and Azure Pipelines together.
You can deploy a React Static Web Apps from Azure using Pipelines as follows:
name: Azure Static Web Apps CI/CD
#
# Trigger off of changes in master or another branch(s)
#
trigger:
branches:
include:
- TestBranch
jobs:
- job: build_and_deploy_job
displayName: Build and Deploy Test Web App
condition: or(eq(variables['Build.Reason'], 'Manual'),or(eq(variables['Build.Reason'],'PullRequest'),eq(variables['Build.Reason'], 'IndividualCI')))
pool:
vmImage: ubuntu-latest
variables:
- group: <Name of your Static Web App Resource Group>
steps:
- checkout: self
submodules: true
- task: AzureStaticWebApp#0
inputs:
azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_TOKEN_#####)
# Details at https://aka.ms/swaworkflowconfig
app_location: "/" # App source code path
api_location: "" # Api source code path - optional
output_location: "build" # Built app content directory - optional
app_build_command: 'chmod 755 scripts/*.sh;./scripts/WebAppBuild.sh prod'
You will first need to set up a connection in Azure->Settings->Pipelines->Service Connections. Use the Pipeline wizard to set up all the initial YML.
The key for me was to run my own build in WebAppBuild.sh which basically runs "npm run build". My repo has a scripts folder. The job/task performed the rest of the install
I have a repo in Azure devops which is using 'ant all' command to build an ear file. This ear file contain should a war file built from another repo in the azure.
How can I include this war file in the build?
Thanks.
If your war file is built from code hosted in another repo and not is a part of the repo itself. You can publish pipeline artifact and download it in your next pipeline. Here you have doc article about this. And here description of the task itself.
In short to publish you should add code like this:
steps:
- publish: $(System.DefaultWorkingDirectory)/bin/WebApp
artifact: WebApp
and to download:
# Download artifacts from a specific pipeline.
- task: DownloadPipelineArtifact#2
inputs:
source: 'specific'
project: 'FabrikamFiber'
pipeline: 12
runVersion: 'latest'
If you mean the war file is already in another repo in the same organization, you could check multiple checkout, by using multiple checkout steps in your pipeline, you can fetch and check out other repositories in addition to the one you use to store your YAML pipeline.
steps:
- checkout: git://MyProject/MyRepo # Azure Repos Git repository in the same organization
- checkout: self
What I want to achieve:
I have a repository on Azure DevOps which hosts my web application. I wrote a test suite for UI Automation using Cypress. I created a separate repository for my test cases to check if they are working properly or not. I created a pipeline which has the following content:
trigger:
- manual-tests
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install'
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'run test'
continueOnError: true
- task: PublishTestResults#2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/test-output-*.xml'
testRunTitle: 'My Test Cases'
I have a trigger set to a branch of the repository in which my UI Automation code is stored. What I want is, to trigger my automation script, when there is a push on some branch of the web application repository. Is there a way of doing this? Can we store our test case files in the application repository and give the path of the test script?
It seems that the UI Automation Repo and Web Application Repo are two separate repos.
To trigger my automation script, when there is a push on some branch of the web application repository. Is there a way of doing this?
The function: "trigger a pipeline from a different repo" is not available now.
This feature is still under development. Multi-repository support for YAML pipelines will be available soon for azure devops service.
Please check the function:"Multi-repository support for YAML pipelines" in Azure DevOps Feature Timeline 2020 Q2. This feature will roll out to everyone by the end of July 2020.
Workaround:
You could try to use the Pipeline triggers.
Here are the steps:
Step1: Create a pipeline with web application repository, then you could set the trigger branch.
Step2: Add the Pipeline trigger in the Yaml file (UI Automation Repo).
For example:
resources:
pipelines:
- pipeline: Name
source: Pipeline name
trigger:
branches:
- releases/*
- master
When you make changes in web application repository, the pipeline with the web application will be triggered.
After running the pipeline , the pipeline with UI Automation repo will be triggered.
Can we store our test case files in the application repository and give the path of the test script?
Of cource. You can do it.
If you want to use the test file in the pipeline (UI Automation repo), you could add the repo resouces in the pipeline.
For example:
resources:
repositories:
- repository: MyAzureReposGitRepository
type: git
name: MyProject/WebapplicationRepo
...
steps:
- checkout: MyAzureReposGitRepository
Note: the repo will be check out to the Agent Source Folder.
Hope this helps.
I have separate yaml pipelines for CI and CD in Azure DevOps Services.
CI pipeline will publish an artifact to a file share location. \fileshare\project
And in the CD pipeline I am using the CI pipeline as resource so that I can deploy the artifact produced from the CI pipeline.
resources:
pipelines:
- pipeline: POC_pipeline # identifier for the pipeline resource
source: CI-pipeline_YAML # source pipeline definition name
My question is how can I download this artifact and what's the pre-defined variable name to get the path of the published artifact from CI-pipeline.
I tried using but it doesn't download anything, this only works when I push the artifact to Azure DevOps.
steps:
- download: POC_pipeline
It seems download task cannot download artifacts that published to a file share. I can reproduce the same issue. You can report this problem(Click Report a problem and choose Azure devops) to Microsoft development team.
As workaround, you can use Download Fileshare Artifacts task to download fileshare artifacts.
- task: DownloadFileshareArtifacts#1
inputs:
filesharePath: '\fileshare\project'
artifactName: artifactName
downloadPath: $(Build.ArtifactStagingDirectory)
The artifacts will be downloaded to folder specified in downloadPath. In above example you will find the artifacts in $(Build.ArtifactStagingDirectory)/artifactName (ie. C:\agent\_work\2\a\artifactName)
Check here to find more predefined variables.
You can also use Download Pipeline Artifacts task to download the fileshare artifacts. You need to specify the source as specific, and other project, pipeline,runVersion attributes. See below:
- task: DownloadPipelineArtifact#2
inputs:
source: specific
project: yourProjectName
pipeline: CI-pipeline_YAML
runVersion: latest
path: $(Build.ArtifactStagingDirectory)
The artifacts will be downloaded to folder specified in path.
Noted: you need to run your pipeline on self-hosted agents which can access the file share.(It will fail with error `Unable to read directory \fileshare\project" on cloud agents).
I want to use VSTS to build and deploy my app (to FTP) when Update the master branch of my project. I have the script below. It works in that it triggers and builds but then fails to deploy because it can't find the files and I don't know what values to enter. I get the error below.
When VSTS builds, where does it put the build files?
I've watched youtube but all the examples are old and don't reflect how VSTS works right now so I'm totally stuck. There are no articles here that reflect how VSTS works right now and the Microsoft pages are no help either.
I'm running out of articles to review and am now pretty much guessing, so any help would be very much appreciated.
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: FtpUpload#2
inputs:
credentialsOption: 'inputs'
serverUrl: 'ftp://xxxxxxx.xxxxxxxx.xxxxx/'
username: 'xxxxxxxxx'
password: 'xxxxxxxxxx'
rootDirectory: '/'
filePatterns: '**'
remoteDirectory: '/'
clean: false
cleanContents: true
preservePaths: false
trustSSL: false
I changed to this
rootDirectory: $(Agent.BuildDirectory)
and tried this
rootDirectory: $(Build.StagingDirectory)
And now the build succeeds but now I get this error/warning. Nothing is deployed.
When you set system.debug=true, then open the log for detailed compile process, you could see:
It is looking for directory '/' which you specified in the task. But, unfortunately, the content obtained with / is not any part of your repos. Then the server tell you sorry, can not find such file or directory in your repos.
This parameter is getting files or folders from your VSTS repos, so here you need use some words to let server know what you want to take from Repos.
(1) Since this task is in your build pipeline, you could use $(Build.SourcesDirectory) to represent for your whole repos.
(2) Also, if you just want to copy part of repos, such as folder or file, just input them with relative path. For example:
Upload the file upload.json which under the folder jobs, just
input rootDirectory: jobs/upload.json.
Upload one folder or file which in the root path of Repos, just input
rootDirectory: {folder name}, or rootDirectory: {folder name}. Like: rootDirectory: jobs, or rootDirectory: web.config