Employing a tool in the upcoming project that is scheduled to execute on an SSH runner in GitLab encounters issues

Currently, I am utilizing the self-managed version 14.6 of GitLab. In my .gitlab-ci.yaml pipeline file, I have defined two jobs: build and deploy. The build job runs on a docker executor through gitlab-runner and generates an artifact named build/, which contains nodejs codes and is stored in the working directory of the gitlab-runner server. My intention is to utilize this artifact in the subsequent job where an ssh executor is used to serve web content - essentially, the ssh-executor represents a remote nginx server. Unfortunately, when executing the command cp build/ /to/ssh/executor/path, I encounter the following error message:

cp: cannot stat ‘src/build’: No such file or directory
.

Below are the configurations from my pipeline yaml:

build react job:
    stage: build
    script:
        - npm install 
        - npm run build --scripts-prepend-node-path=auto
    artifacts:
        paths:
            - build/
        untracked: true
deploy on production:
    stage: deploy
    tags:
        - my-srv  # this refers to the ssh-executor runner
    rules:
        - if: ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "develope")
    script:
        - cp -r build /path/on/my/server/web/content
        - docker-compose up -d
    needs:
        - job: build react job
          artifacts: true

In an attempt to establish a relationship between the deploy stage and the build stage, I have experimented with the dependencies: and needs sections, but unfortunately, none of these approaches yielded the desired results. Shown below are the configurations for the my-srv runner found in /etc/gitlab-runner/config.toml:

[[runners]]
  name = "my-srv"
  url = "http://gitlab.example.com/"
  token = "s8XljhkxJd-qj7WxCcew"
  executor = "ssh"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.ssh]
    user = "user"
    password = "pass"
    host = "172.20.ip.addr"
    port = "22"
    identity_file = "/home/gitlab-runner/.ssh/id_rsa"

Any insights or suggestions would be greatly appreciated.

Answer №1

Your current pipeline code appears to be intact, and supports artifact sharing for SSH executor. To troubleshoot the issue at hand, consider the following steps:

To start with, remove the untracked: true statement as it may not be necessary. The artifacts specified in the paths: statement cover the files needed for subsequent jobs. Including untracked: true could introduce additional untracked files unrelated to your project, impacting job performance.

Next, investigate why the deploy on production job running on the remote system 172.20.ip.addr is encountering an error regarding the absence of the src/build directory. This could be due to three possible reasons:

  1. The build directory was not uploaded to the GitLab server as an artifact.
  2. The build directory was not transferred to the remote system by GitLab (potentially a bug).
  3. The build directory was copied to a different location or referenced from an unexpected path.

You can verify (1) by checking the presence of artifacts on the job details page, accessible from the right side.

To validate (2), create a third job:

check-artifacts:
  stage: deploy
  needs:
    - job: build react job
      artifacts: true
  script:
    - echo "Verifying availability of 'build' dir by GitLab..."
    - ls -lart $CI_PROJECT_DIR/build
    - find $CI_PROJECT_DIR -type d -name build

If this job, executed by the same runner as the initial one, locates the build directory, then the artifact transfer is functioning correctly. Review the log for confirmation that GitLab attempted to download artifacts.

A similar approach can be taken for (3):

deploy on production:
  stage: deploy
  tags:
    - my-srv  # utilizing ssh-executor runner
  rules:
    - if: ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "develop")
  before_script:
    - echo "Running as user $USER on host $HOSTNAME in dir $PWD"
    - find $CI_PROJECT_DIR -type d -name build    # check common locations first...
    - find / -type d -name build 2>/dev/null      # ... explore alternative paths
  script:
    - cp -r build /path/on/my/server/web/content
    - docker-compose up -d
  needs:
    - job: build react job
      artifacts: true

If errors arise in the before_script section while the previous job succeeds, there may be an issue specific to sharing artifacts with SSH executor runners. Conversely, if the helper job fails, investigate general concerns related to artifact upload/download/sharing in GitLab logs for relevant insights.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When referencing a particular React commit in package.json, it may result in the installation of react-tools instead of react itself

After including the following line in my package.json: "react": "git://github.com/facebook/react.git#08e4420019f74b7c93e64f59c443970359102530" When I execute npm install, I notice that node_modules/react-tools has been installed instead of node_modules/r ...

"Exploring the world of npm packages alongside the powerful angular-cli tool

Is it better to package angular2 components in an npm module with the source files (*.ts, *.css, *.html) or the webpack compiled version for use in applications compiled with angular-cli@webpack? What should actually be published in the npm package? The r ...

Error encountered during Angular boot process due to npm running lifecycle script ELIFECYCLE

I encountered an issue while trying to boot up my Angular project. I attempted to install necessary plugins, but ran into some errors. { "name": "portal-app", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng ser ...

Leveraging the power of node pkg to generate standalone executables while configuring npm

I have successfully used pkg to create an executable file for my node js application. Everything is working fine in that aspect. However, I am also utilizing the config module to load yaml configuration files based on the environment. During the packaging ...

The gitlab-ci job remains successful, but unfortunately, the test ends in failure

My goal is to ensure that a failed test in my pipeline results in job failure, providing me with control over the process. However, I'm encountering an issue because the tests are running within a "docker in docker" environment, causing the job not to ...

When multiple files are used, .env does not return any values

Having trouble with two files utilizing .env, as both are returning undefined for variables. I attempted setting a root .env file for both the front-end and backend, but still facing issues with loading the .env variables. In the frontend, any .env variab ...

Encountering difficulties with utilizing NPM on Ubuntu operating system

I seem to be experiencing issues with using NPM. Every time I try to run npm -v or npm install, an error occurs. The specific error message is: bash: /usr/local/bin/npm: /usr/local/bin/node: bad interpreter: No such file or directory Even after attemptin ...

Exploring relative path depths using Gulp: A guide

I'm working on a project with a central repository that contains core files at the root level, as well as separate theme folders each with their own unique settings and build processes. The structure of the project looks like this: core/ themes/ ...

Which option is better: installing plotly.js or plotly.js-dist using npm?

When it comes to plotly.js and plotly.js-dist, what exactly sets these two packages apart from each other? Notably, the installation instructions for plotly.js on npmjs.org specify running 'npm install plotly.js-dist' - why is this necessary? W ...

Encountering issues with installing packages while creating a new Angular 9 project

Recently I updated to node version 12.16.1 (LTS) and Angular CLI version 9.0.3. After creating a new project with the CLI, all files in the root folder are generated but it gets stuck during the installation of node packages. Has anyone else encountered t ...

Issue: React build script does not support conversion from 'BigInt' to 'number' error

After developing the UI using create-react-app, I encountered an issue. The UI works fine with the normal npm start command, but when I try to build it with npm run build, I get an error saying 'Conversion from 'BigInt' to 'number' ...

Discovered a critical vulnerability that requires your attention. Execute `npm audit fix` to resolve the issue, or use `npm audit` for more information

After attempting to install mysql using 'npm install mysql', I encountered an error message stating: "found 1 critical severity vulnerability run npm audit fix to fix them, or npm audit for details" Following this, I proceeded with 'npm au ...

The sluggish development process on SAP Cloud Platform is caused by the lengthy npm install

Our team relies on grunt to construct our HTML5 Applications within the SAP Hana Cloud Platform. However, we have encountered significant delays in the process, often resulting in the build timing out after 6 minutes for even small applications. The prima ...

The previous build of node/npm is utilizing -lstdc++ which is incompatible with macOS Catalina

Encountering issues when using an outdated version of node (5.x) on macOS Catalina, attempting to run npm install on a package triggers the installation of node-gyp, resulting in an error. fatal error: 'algorithm' file not found After researc ...

Powershell is unable to detect NPM modules that have been installed locally in the bin directory

When creating a local NPM project designed to act as an installable NPM CLI command on Windows, I encountered issues with local testing not behaving as expected. To showcase this problem, I have set up this GitHub repository. Take a look at the provided r ...

Experience the simplicity of running basic Javascript Scratch code within IntelliJ IDEA Ultimate

Is there a straightforward way to run and debug a basic JavaScript code in IntelliJ Idea Ultimate without the need for additional setup like creating an HTML file or npm project? I'm looking to avoid boilerplate tasks and wondering if there's an ...

Using the connect-flash package to display a flash message on the website

Currently working on learning expressjs and mongodb through various exercises. I am attempting to display flash messages whenever a new item is added, updated, or deleted from the database. Struggling with getting it to work as expected without any errors ...

Is there a way to determine which version of ESLint is currently running on Visual Studio 2019?

While attempting to run ESLint on Visual Studio 2019, everything goes smoothly until I add eslint-plugin-prettier to my package.json file. At that point, an error arises. internal-error | (ESLint) Failed to load plugin prettier: Cannot find module &apos ...

Generating a package.json file that includes a comprehensive list of all development dependencies

My Inquiry I've been pondering whether it's possible to include all the necessary devDependencies within the package.json file generated by running npm init in the Terminal for Gulp projects. Can these dependencies be pre-listed in the file inst ...

Struggling with "Content" not being recognized in Typescript PouchDB transpilation errors?

I have been diligently working on an Ionic app for the past three months with no major issues during development or deployment to mobile devices. However, yesterday I encountered a frustrating NPM dependency problem while trying to deploy to mobile. In an ...