azure pipeline publish dotnet core remote host - .net-core

I'm using azure pipeline to build and deploy my Asp.net core project to remote server,I successfully build and publish files to artifact staging folder ,and then I use ftp upload task to upload files to remote server, but the problem is all the files are in the same folder and wwwroot folder is not there so website breaks because of the css and js files.
but when I use the 'zipAfterPublish=true', it generates the right files and folder
this is my yml file :
`
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
ftpServer : '*****'
ftpUsername : '*****'
ftpPassword : '****'
ftpRootDirectory : '*****'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
arguments: '-c $(buildConfiguration) -o $(Build.ArtifactStagingDirectory)/published'
publishWebProjects: true
zipAfterPublish: false
displayName: 'publish $(Build.ArtifactStagingDirectory)/published'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/published'
publishLocation: 'pipeline'
displayName: 'publish artifact to pipeline'
- task: FtpUpload#2
inputs:
credentialsOption: 'inputs'
serverUrl: '$(ftpServer)'
username: '$(ftpUsername)'
password: '$(ftpPassword)'
rootDirectory: '$(Build.ArtifactStagingDirectory)'
remoteDirectory: '$(ftpRootDirectory)'
filePatterns: '**/*.htm'
clean: false
cleanContents: false
preservePaths: false
trustSSL: false
displayName: 'Upload App_Offline'
- task: FtpUpload#2
inputs:
credentialsOption: 'inputs'
serverUrl: '$(ftpServer)'
username: '$(ftpUsername)'
password: '$(ftpPassword)'
rootDirectory: '$(Build.ArtifactStagingDirectory)/published'
filePatterns: '**'
remoteDirectory: '$(ftpRootDirectory)'
clean: false
cleanContents: false
preservePaths: false
trustSSL: false
displayName: 'Upload Publish Files'
- task: FtpUpload#2
inputs:
credentialsOption: 'inputs'
serverUrl: '$(ftpServer)'
username: '$(ftpUsername)'
password: '$(ftpPassword)'
rootDirectory: '$(Build.ArtifactStagingDirectory)'
filePatterns: '**.ddddd'
remoteDirectory: '$(ftpRootDirectory)'
clean: false
cleanContents: false
preservePaths: false
trustSSL: false
customCmds: 'DELE /***/App_Offline.htm'
displayName: 'Delete App_Offline'
`
I already tried a few things but none of them worked for me .
help please ?

As #lexli shared, you can check the "preservePaths":
For example, suppose your source folder is /home/user/source/, which contains the file foo/bar/foobar.txt, and your remote directory is: /uploads/. If this boolean is selected, the file is uploaded to /uploads/foo/bar/foobar.txt. If this boolean is not selected, the file is uploaded to /uploads/foobar.txt.
For more information, you could refer to: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/ftp-upload-v2?view=azure-pipelines

Related

What is the correct way to use GHA environment variables in code?

I want to define an environment variable in a Github actions workflow file, and then use that variable in a Nextjs application.
Latest effort is: in GHA workflow, I send an environment variable like this:
env:
ENV_VAR: value
and then under pages/index.js I want to do something like:
export default function Home() {
return (
<div>{process.env.ENV_VAR}</div>
)
}
But when I deploy the application and navigate to the page, I just observe the value momentarily and then it disappears. What am I doing wrong here?
Turns out the variable I was trying to pass was available at build time, so what I could do was something like this:
.github/workflow/.yaml file
name: Deploy Next.js site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
env:
DEPLOY_ENV: PROD
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Detect package manager
id: detect-package-manager
run: |
echo "BRANCH: $GITHUB_REF_NAME"
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "::set-output name=manager::yarn"
echo "::set-output name=command::install"
echo "::set-output name=runner::yarn"
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "::set-output name=manager::npm"
echo "::set-output name=command::ci"
echo "::set-output name=runner::npx --no-install"
exit 0
else
echo "Unable to determine packager manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node#v3
with:
node-version: "16"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Setup Pages
uses: actions/configure-pages#v2
with:
# Automatically inject basePath in your Next.js configuration file and disable
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
#
# You may remove this line if you want to manage the configuration yourself.
static_site_generator: next
- name: Restore cache
uses: actions/cache#v3
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
- name: Static HTML export with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next export
- name: Upload artifact
uses: actions/upload-pages-artifact#v1
with:
path: ./out
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages#v1
and then in a nextjs page I could do this:
import React from 'react';
export const getStaticProps = () => {
return {
props: {
deployEnv: process.env.DEPLOY_ENV
}
}
}
export default function Home({ deployEnv }: {deployEnv: string}) {
return (
<div>{deployEnv}</div>
)
}

I am writng the gitlab pipeline to deploy terraform files in nexus repo, I want to make it incremental versioning of my folder. I am confused help me

variables:
TF_ROOT: ${CI_PROJECT_DIR}
TF_CLI_CONFIG_FILE: $CI_PROJECT_DIR/.terraformrc
TF_IN_AUTOMATION: "true"
ARM_SUBSCRIPTION_ID: ""
ARM_TENANT_ID: ""
NEXUS_URL: ""
cache:
key: "${TF_ROOT}"
paths:
- ${TF_ROOT}/.terraform/
.terraform-setup-and-init: &init
ls -al
source <(curl -O -k $NEXUS_URL)
ls -al
chmod +x setup-terraform.sh
ls -al *.sh
source ./setup-terraform.sh
export HTTPS_PROXY=
terraform init -var-file="./environments/US/sev.tfvars"
.validate:
stage: validate
script:
- *init
- terraform validate
.build:
stage: build
script:
- *init
- echo "executing terraform plan, needs provider credentials... Skipping"
# - terraform plan -out="plan.cache"
# - terraform show -json "plan.cache" > plan.json
artifacts:
paths:
- ${TF_ROOT}/plan.cache
reports:
terraform: ${TF_ROOT}/plan.json
.deploy:
stage: deploy
script:
- *init
# - terraform apply -input=false "plan.cache"
only:
variables:
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
stages:
validate
build
deploy
tf validate:
extends: .validate
tf plan:
extends: .build
tf apply:
extends: .deploy
dependencies:
- tf plan

DOTNETCORECLI#2 Publish succeeds but no artifacts

I have a legacy project and want to get into Azure Devops pipelines. I have a build pipeline setup and build seems to succeed. I've added a DotnetcoreCli Publish task and this succeeds but I never have any artifacts available after running so can't implement a Release pipeline.
Wondering if anyone can spot anything daft I've done?
These are the Tasks defined in my pipeline:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '$(solution)'
arguments: '--configuration $(buildConfiguration)'
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/UAT'))
inputs:
command: 'publish'
publishWebProjects: true
configuration: $(BuildConfiguration)
arguments: '--output $(Build.ArtifactStagingDirectory) --verbosity detailed'
zipAfterPublish: false # We want individual files published, not a zip
This is the end of the trace of my Publish task:
(entry point): 2021-09-09T08:57:26.4983992Z Task "Message"
2021-09-09T08:57:26.4984515Z MYOrg.MyApp.UI ->
D:\a\1\a\Staging\MYOrg.MyApp.UI\ 2021-09-09T08:57:26.4985051Z
Done executing task "Message". 2021-09-09T08:57:26.4985655Z
1>Done building target "Publish" in project "MYOrg.MyApp.UI.csproj".
2021-09-09T08:57:26.4986271Z Target
"_InitProjectCapabilityProperties" skipped. Previously built
successfully. 2021-09-09T08:57:26.4991632Z 1>Target
"_InitPublishIntermediateOutputPath" in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\DotNetCLIToolTargets\Microsoft.NET.Sdk.DotNetCLITool.targets"
from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (target
"_AspNetCoreProjectSystemPostPublish" depends on it):
2021-09-09T08:57:26.4992847Z Task "ConvertToAbsolutePath"
2021-09-09T08:57:26.4993300Z Done executing task
"ConvertToAbsolutePath". 2021-09-09T08:57:26.4993889Z 1>Done
building target "_InitPublishIntermediateOutputPath" in project
"MYOrg.MyApp.UI.csproj". 2021-09-09T08:57:26.4994986Z 1>Target
"_TransformWebConfig" in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets" from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (target
"_AspNetCoreProjectSystemPostPublish" depends on it):
2021-09-09T08:57:26.4996207Z Using "TransformWebConfig" task
from assembly
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0....\tools\netcoreapp1.0\Microsoft.NET.Sdk.Publish.Tasks.dll".
2021-09-09T08:57:26.4997005Z Task "TransformWebConfig"
2021-09-09T08:57:26.5010124Z Configuring the following
project for use with IIS: 'D:\a\1\a\Staging\MYOrg.MyApp.UI'
2021-09-09T08:57:26.5010856Z Updating web.config at
'D:\a\1\a\Staging\MYOrg.MyApp.UI\web.config'
2021-09-09T08:57:26.5129541Z Configuring project completed
successfully 2021-09-09T08:57:26.5140303Z Done executing task
"TransformWebConfig". 2021-09-09T08:57:26.5143720Z 1>Done
building target "_TransformWebConfig" in project
"MYOrg.MyApp.UI.csproj". 2021-09-09T08:57:26.5145086Z 1>Target
"_TransformAppSettings" in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets" from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (target
"_AspNetCoreProjectSystemPostPublish" depends on it):
2021-09-09T08:57:26.5146333Z Task "TransformAppSettings"
skipped, due to false condition; ('$(_IsAspNetCoreProject)' == 'true'
And '$(IsTransformAppSettingsDisabled)' != 'true' And
#(DestinationConnectionStrings) != '') was evaluated as ('true' ==
'true' And '' != 'true' And != ''). 2021-09-09T08:57:26.5153800Z
1>Done building target "_TransformAppSettings" in project
"MYOrg.MyApp.UI.csproj". 2021-09-09T08:57:26.5156303Z 1>Target
"_GenerateEFSQLScripts" in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets" from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (target
"_AspNetCoreProjectSystemPostPublish" depends on it):
2021-09-09T08:57:26.5157868Z Task "GenerateEFSQLScripts"
skipped, due to false condition; ('$(_IsAspNetCoreProject)' == 'true'
And '$(IsGenerateEFSQLScriptsDisabled)' != 'true' And #(EfMigrations)
!= '') was evaluated as ('true' == 'true' And '' != 'true' And !=
''). 2021-09-09T08:57:26.5180482Z 1>Done building target
"_GenerateEFSQLScripts" in project "MYOrg.MyApp.UI.csproj".
2021-09-09T08:57:26.5183010Z 1>Target "_GenerateRunCommandFile"
in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets" from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (target
"_AspNetCoreProjectSystemPostPublish" depends on it):
2021-09-09T08:57:26.5185028Z Task "GenerateRunCommandFile"
skipped, due to false condition; ('$(_IsWebJobProject)' == 'true' And
'$(IsGenerateRunCommandFileDisabled)' != 'true') was evaluated as (''
== 'true' And '' != 'true'). 2021-09-09T08:57:26.5185862Z 1>Done building target "_GenerateRunCommandFile" in project
"MYOrg.MyApp.UI.csproj". 2021-09-09T08:57:26.5186601Z Target
"_PublishFiles" skipped, due to false condition; ('$(PublishProtocol)'
!= 'FileSystem' And '$(PublishProtocol)' != '') was evaluated as
('FileSystem' != 'FileSystem' And 'FileSystem' != '').
2021-09-09T08:57:26.5187820Z 1>Target
"_AspNetCoreProjectSystemPostPublish" in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\DotNetCLIToolTargets\Microsoft.NET.Sdk.DotNetCLITool.targets"
from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (target
"_DotNetCLIPostPublish" depends on it): 2021-09-09T08:57:26.5188885Z
1>Done building target "_AspNetCoreProjectSystemPostPublish" in
project "MYOrg.MyApp.UI.csproj". 2021-09-09T08:57:26.5189885Z
1>Target "AfterPublish" in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets"
from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (target
"_DotNetCLIPostPublish" depends on it): 2021-09-09T08:57:26.5190833Z
1>Done building target "AfterPublish" in project
"MYOrg.MyApp.UI.csproj". 2021-09-09T08:57:26.5191798Z 1>Target
"_DotNetCLIPostPublish" in file
"C:\hostedtoolcache\windows\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\DotNetCLIToolTargets\Microsoft.NET.Sdk.DotNetCLITool.targets"
from project "D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (entry
point): 2021-09-09T08:57:26.5192771Z 1>Done building target
"_DotNetCLIPostPublish" in project "MYOrg.MyApp.UI.csproj".
2021-09-09T08:57:26.5193415Z 1>Done Building Project
"D:\a\1\s\MYOrg.MyApp.UI\MYOrg.MyApp.UI.csproj" (Publish target(s)).
2021-09-09T08:57:26.5210238Z 2021-09-09T08:57:26.5225190Z Build
succeeded. 2021-09-09T08:57:26.5260048Z 0 Warning(s)
2021-09-09T08:57:26.5260950Z 0 Error(s)
After dontet publish command you need to make Azure Pipeline artifact.
You can do this in this way:
- publish: $(Build.ArtifactStagingDirectory)
artifact: WebApp
Here you have documentation about this. After that, you will get an artifact available for release pipeline.

How can I found that the Rscript have been run successfully on the docker by the CWL?

I have written the CWL code which runs the Rscript command in the docker container. I have two files of cwl and yaml and run them by the command:
cwltool --debug a_code.cwl a_input.yaml
I get the output which said that the process status is success but there is no output file and in the result "output": null is reported. I want to know if there is a method to find that the Rscript file has run on the docker successfully. I want actually know about the reason that the output files are null.
The final part of the result is:
[job a_code.cwl] {
"output": null,
"errorFile": null
}
[job a_code.cwl] Removing input staging directory /tmp/tmpUbyb7k
[job a_code.cwl] Removing input staging directory /tmp/tmpUbyb7k
[job a_code.cwl] Removing temporary directory /tmp/tmpkUIOnw
[job a_code.cwl] Removing temporary directory /tmp/tmpkUIOnw
Removing intermediate output directory /tmp/tmpCG9Xs1
Removing intermediate output directory /tmp/tmpCG9Xs1
{
"output": null,
"errorFile": null
}
Final process status is success
Final process status is success
R code:
library(cummeRbund)
cuff<-readCufflinks( dbFile = "cuffData.db", gtfFile = NULL, runInfoFile = "run.info", repTableFile = "read_groups.info", geneFPKM = "genes.fpkm_trac .... )
#setwd("/scripts")
sink("cuff.txt")
print(cuff)
sink()
My cwl file code is:
class: CommandLineTool
cwlVersion: v1.0
id: cummerbund
baseCommand:
- Rscript
inputs:
- id: Rfile
type: File?
inputBinding:
position: 0
- id: cuffdiffout
type: 'File[]?'
inputBinding:
position: 1
- id: errorout
type: File?
inputBinding:
position: 99
prefix: 2>
valueFrom: |
error.txt
outputs:
- id: output
type: File?
outputBinding:
glob: cuff.txt
- id: errorFile
type: File?
outputBinding:
glob: error.txt
label: cummerbund
requirements:
- class: DockerRequirement
dockerPull: cummerbund_0
my input file (yaml file) is:
inputs:
Rfile:
basename: run_cummeR.R
class: File
nameext: .R
nameroot: run_cummeR
path: run_cummeR.R
cuffdiffout:
- class: File
path: cuffData.db
- class: File
path: genes.fpkm_tracking
- class: File
path: read_groups.info
- class: File
path: genes.count_tracking
- class: File
path: genes.read_group_tracking
- class: File
path: isoforms.fpkm_tracking
- class: File
path: isoforms.read_group_tracking
- class: File
path: isoforms.count_tracking
- class: File
path: isoform_exp.diff
- class: File
path: gene_exp.diff
errorout:
- class: File
path: error.txt
Also, this is my Dockerfile for creating image:
FROM r-base
COPY . /scripts
RUN apt-get update
RUN apt-get install -y \
libcurl4-openssl-dev\
libssl-dev\
libmariadb-client-lgpl-dev\
libmariadbclient-dev\
libxml2-dev\
r-cran-plyr\
r-cran-reshape2
WORKDIR /scripts
RUN Rscript /scripts/build.R
ENTRYPOINT /bin/bash
I got the answer!
There were some problems in my program.
1. The docker was not pulled correctly then the cwl couldn't produce any output.
2. The inputs and outputs were not defined mandatory. So I got the success status in the case which I did not have proper inputs and output.

Requirejs optimization with grunt

I am trying to create a requirejs optimization config with grunt and almond. Here's the config:
requirejs:
build:
options:
almond: true
dir: 'build'
appDir: ''
baseUrl: '../client'
wrap: true
include: '../client/main'
keepBuildDir: true
paths:
underscore: 'client/vendor/underscore'
jquery : 'client/vendor/jquery'
backbone : 'client/vendor/backbone'
Folder Structure:
Error:
C:\Users\User\Documents\Source\Project>grunt requirejs
Running "requirejs:build" (requirejs) task
>> Error: ENOENT, no such file or directory
>> 'C:\Users\User\Documents\Source\Project\build\models\MenuItem.js'
>> In module tree:
>> ../client/main
Warning: RequireJS failed. Use --force to continue.
Main.js code (written in coffeescript)
requirejs.config(
baseUrl: "client"
shim:
'backbone':
deps: ['jquery']
exports: 'Backbone'
'jquery':
exports: '$'
'underscore':
exports: '_'
paths:
jquery: 'vendor/jquery-1.11.0'
underscore: 'vendor/underscore'
backbone: 'vendor/backbone'
)
define 'start', ()->
window.types =
Models: {}
Collections: {}
Views: {}
null
require ['models/MenuItem', 'views/MenuItem'], (MenuItemModel, MenuItemView)->
view = new MenuItemView(
new MenuItemModel(),
"#app",
'first'
)
view.render();
null
I want to compile my entire project spread across multiple js files into a single file in a way that requirejs would not be needed. I am trying to do this using almond js but the build task does not look for referenced files relative to the path of referring file. Please help me with the correct configuration.

Resources