.net-coregitlabgitlab-pipelines

Duplicate part of gitlab repository to another repository inside gitlab


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/'


Solution

  • Use GitLab Artifacts

    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 published 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).

    Caveats:

    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.


    Use git inside your job

    Alternatively, since you want to push these to the other repository, then things get more tricky. You need to do these things:

     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'
    

    Caveats: