scp 在 Gitlab CI 作业期间找不到当前目录

问题描述 投票:0回答:2

我正在使用 Gitlab CI 构建并部署到服务器。一切都运行良好,除了最后我想通过

scp
将构建的文件复制到我的服务器。

这里是

.gitlab-ci.yml

image: trion/ng-cli-karma

cache:
  paths:
    - node_modules/

before_script:
  - apt-get update -qq && apt-get install -y -qq sshpass

deploy_stage:
  stage: deploy
  environment: Staging
  only:
    - master
  script:
    - rm ./package-lock.json
    - npm install
    - npm run build-dev
    - cd dist/
    - ls
    - sshpass -V
    - export SSHPASS=$USER_PASS 
    - sshpass -e scp -o stricthostkeychecking=no -r . [email protected]:/var/www/html

这是输出

Running with gitlab-runner 12.3.0 (a8a019e0)
  on docker-auto-scale ed2dce3a
Using Docker executor with image trion/ng-cli-karma ...
Pulling docker image trion/ng-cli-karma ...
Using docker image sha256:037ee824704dc86fa1b69cb50bc9445b0aa02c2fe7708462bdb2ca5584bde7bd for trion/ng-cli-karma ...
Running on runner-ed2dce3a-project-14638464-concurrent-0 via runner-ed2dce3a-srm-1570180837-5976d76d...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/Axiol/my-really-awesome-project/.git/
Created fresh repository.
From https://gitlab.com/Axiol/my-really-awesome-project
 * [new branch]      master     -> origin/master
Checking out f1cfb167 as master...

Skipping Git submodules setup
Checking cache for default...
Downloading cache.zip from https://storage.googleapis.com/gitlab-com-runners-cache/project/14638464/default 
Successfully extracted cache
$ apt-get update -qq && apt-get install -y -qq sshpass
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package sshpass.
(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 26118 files and directories currently installed.)
Preparing to unpack .../sshpass_1.06-1_amd64.deb ...
Unpacking sshpass (1.06-1) ...
Setting up sshpass (1.06-1) ...
$ rm ./package-lock.json
$ npm install
npm WARN [email protected] requires a peer of sass@^1.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

audited 5973 packages in 5.325s
found 0 vulnerabilities

$ npm run build-dev

> [email protected] build-dev /builds/Axiol/my-really-awesome-project
> webpack -d --mode development

Hash: 2441bcfb3aef68b9ec4f
Version: webpack 4.41.0
Time: 633ms
Built at: 10/04/2019 9:22:44 AM
    Asset      Size  Chunks             Chunk Names
bundle.js  41.6 KiB    main  [emitted]  main
Entrypoint main = bundle.js
[./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/reset.scss] 1.26 KiB {main} [built]
[./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/styles.scss] 306 bytes {main} [built]
[./src/index.js] 76 bytes {main} [built]
[./src/reset.scss] 444 bytes {main} [built]
[./src/styles.scss] 445 bytes {main} [built]
    + 2 hidden modules
$ cd dist/
$ ls
bundle.js
img
index.html
$ sshpass -V
sshpass 1.06
(C) 2006-2011 Lingnu Open Source Consulting Ltd.
(C) 2015-2016 Shachar Shemesh
This program is free software, and can be distributed under the terms of the GPL
See the COPYING file for more information.

Using "assword" as the default password prompt indicator.
$ export SSHPASS=$USER_PASS
$ sshpass -e scp -o stricthostkeychecking=no -r . [email protected]:/var/www/html
Warning: Permanently added 'my.server' (ECDSA) to the list of known hosts.
scp: error: unexpected filename: .
ERROR: Job failed: exit code 1

我真的不明白

.
怎么会是未定义的。

gitlab gitlab-ci scp
2个回答
1
投票

而不是 .尝试使用 $(pwd) .

sshpass -e scp -o stricthostkeychecking=no -r $(pwd) [email protected]:/var/www/html

0
投票

您还可以使用预定义的 CI/CD 变量 $CI_PROJECT_DIR。这是存储库克隆到的完整路径,也是作业运行的位置。

sshpass -e scp -o stricthostkeychecking=no -r $CI_PROJECT_DIR [email protected]:/var/www/html

参考:https://docs.gitlab.com/ee/ci/variables/predefined_variables.html

© www.soinside.com 2019 - 2024. All rights reserved.