I have a Shared Server running IIS that accepts Git automatic deployment, I am using .Net 2.2. Files will be deployed to the plesk website as soon as they are pushed to the gitlab repository using SSH and WebHooks. So this repository will only have deployed, e.g: dll files. I have another repository for the repository in gitlab.
I am able to publish locally by the command bellow in pipeline.
publish-to-dev:
stage: publish-to-dev
image: mcr.microsoft.com/dotnet/sdk:3.1-focal
script:
- 'dotnet publish -c Release'
Question: How can I create a pipeline command that will copy the deployed files from the code repository to the deployment repository after the deployment command dotnet publish
?
EDIT
Question was answered by Mike bellow, but I am getting an error on the process of copying file, I am getting the message like bellow:
$ cp artifacts/emaua/* deploy/
cp: -r not specified; omitting directory 'artifacts/emaua/cs'
cp: -r not specified; omitting directory 'artifacts/emaua/de'
cp: -r not specified; omitting directory 'artifacts/emaua/es'
cp: -r not specified; omitting directory 'artifacts/emaua/fr'
cp: -r not specified; omitting directory 'artifacts/emaua/it'
cp: -r not specified; omitting directory 'artifacts/emaua/ja'
cp: -r not specified; omitting directory 'artifacts/emaua/ko'
cp: -r not specified; omitting directory 'artifacts/emaua/pl'
cp: -r not specified; omitting directory 'artifacts/emaua/pt-BR'
cp: -r not specified; omitting directory 'artifacts/emaua/refs'
cp: -r not specified; omitting directory 'artifacts/emaua/ru'
cp: -r not specified; omitting directory 'artifacts/emaua/runtimes'
cp: -r not specified; omitting directory 'artifacts/emaua/tr'
cp: -r not specified; omitting directory 'artifacts/emaua/wwwroot'
cp: -r not specified; omitting directory 'artifacts/emaua/zh-Hans'
cp: -r not specified; omitting directory 'artifacts/emaua/zh-Hant'
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
Solved by adding -r
like - 'cp -r path/to/published/files/* deploy/'
The dotnet publish command will build the project and then put the output files to a folder on the build system.
This will be a folder on the GitLab Runner machine that's running the publish-to-dev
job.
If you want to be able to download the publish
ed files from GitLab, then you can use artifacts to specify that the directory containing the published files be zipped up and attached to the job after it completes.
publish-to-dev:
stage: publish-to-dev
image: mcr.microsoft.com/dotnet/sdk:3.1-focal
script:
- 'dotnet publish -c Release'
artifacts:
paths:
- path/to/published/files/
The files will be available as artifacts.zip
on the job (on the right-hand side bar).
This doesn't actually put the published files into the deployment repository. To do that you would have to download the ZIP and then add it to the repo yourself.
git
inside your jobAlternatively, since you want to push these to the other repository, then things get more tricky. You need to do these things:
DEPLOY_REPO_TOKEN
variables
), and use it to authenticate when you do git
operations to the deployment repositorypublish-to-dev
job, git clone
the deployment repository (using the token), git add
the published files, and then git push
, something like this: variables:
DEPLOY_REPO_TOKEN: $DEPLOY_REPO_TOKEN
DEPLOY_REPO_URL: 'gitlab.example.com/group/project/deployment-repository'
publish-to-dev:
stage: publish-to-dev
image: mcr.microsoft.com/dotnet/sdk:3.1-focal
script:
- 'dotnet publish -c Release'
- `git clone https://oauth2:$DEPLOY_REPO_TOKEN@$DEPLOY_REPO_URL.git deploy'
- 'cp -r path/to/published/files/* deploy/'
- 'cd deploy'
- 'git add .'
- 'git commit -m "deployed"'
- 'git push'
mcr.microsoft.com/dotnet/sdk:3.1-focal
image to see if this is dotnet on a Linux (so that the cp
command will work), or if it's a Windows image (requiring copy
instead, and different path separators).git
command to be present, or else you'll have to install that first.