【问题标题】:Jenkins build says successful but no output is seen?詹金斯构建说成功但没有看到输出?
【发布时间】:2022-11-11 04:11:51
【问题描述】:

我正在部署我的 reactjs 应用程序。为此,我编写了管道脚本以从 Jenkins 部署到 EC2 服务器上。

每次构建成功但没有输出。我找不到错误。 当我通过 putty 登录到 EC2 实例并且当我手动部署应用程序时,应用程序正在运行,但是当我在管道中编写并执行时相同的步骤,然后输出不会出现

我已经检查了几种方法但没有用

这是我在直接部署到服务器时使用的简单 Jenkins 文件,因为我正在检查错误

pipeline {
    agent {
        label 'master'
    }
    stages {
        stage('Deploy') { 
            agent {
                label 'testnode'
            }
            steps {
               script{
                    
                    sh """
                        #!/bin/bash
                        ls
                        sudo npm start &
                    """
                    
                }
            }
        }
    }
}

控制台输出

Started by user Mani
Replayed #18
 > git rev-parse --resolve-git-dir /var/lib/jenkins/caches/git-02fb4007d201f8b81dff24c4385bb601/.git # timeout=10
Setting origin to https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git
 > git config remote.origin.url https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git # timeout=10
Fetching origin...
Fetching upstream changes from origin
 > git --version # timeout=10
 > git --version # 'git version 2.32.0'
 > git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials Bitbucket
 > git fetch --tags --force --progress -- origin +refs/heads/*:refs/remotes/origin/* # timeout=10
Seen branch in repository origin/master
Seen 1 remote branch
Obtained Jenkinsfile from 95b8c92cd4dab7a9e6e8d13c81c84bca700dbe36
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/React_master
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: git
using credential Bitbucket
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/React_master/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git # timeout=10
Fetching without tags
Fetching upstream changes from https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git
 > git --version # timeout=10
 > git --version # 'git version 2.32.0'
using GIT_ASKPASS to set credentials Bitbucket
 > git fetch --no-tags --force --progress -- https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision 95b8c92cd4dab7a9e6e8d13c81c84bca700dbe36 (master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 95b8c92cd4dab7a9e6e8d13c81c84bca700dbe36 # timeout=10
Commit message: "Jenkinsfile edited online with Bitbucket"
 > git rev-list --no-walk 95b8c92cd4dab7a9e6e8d13c81c84bca700dbe36 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] node
Running on testnode in /home/ec2-user/workspace/React_master
[Pipeline] {
[Pipeline] checkout
The recommended git tool is: git
using credential Bitbucket
Fetching changes from the remote Git repository
Fetching without tags
 > git rev-parse --resolve-git-dir /home/ec2-user/workspace/React_master/.git # timeout=10
 > git config remote.origin.url https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git # timeout=10
Fetching upstream changes from https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git
 > git --version # timeout=10
 > git --version # 'git version 2.32.0'
using GIT_ASKPASS to set credentials Bitbucket
 > git fetch --no-tags --force --progress -- https://ManiGopal27@bitbucket.org/nariyapratik/econote-web.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision 95b8c92cd4dab7a9e6e8d13c81c84bca700dbe36 (master)
Commit message: "Jenkinsfile edited online with Bitbucket"
[Pipeline] withEnv
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ ls
Jenkinsfile
node_modules
package.json
package-lock.json
public
README.md
serve.json
src
webpack.config.js
yarn.lock
+ sudo npm start
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS


total 39416
    drwxrwxrwx    6 ec2-user ec2-user      265 Jun 21 05:19 .
    drwxrwxr-x    6 ec2-user ec2-user      100 Jun 20 09:19 ..
    -rw-rw-r--    1 ec2-user ec2-user       25 Jun 21 05:14 .env
    drwxrwxrwx    8 ec2-user ec2-user      162 Jun 21 05:20 .git
    -rw-rw-r--    1 ec2-user ec2-user      503 Jun 21 05:14 .gitignore
    -rw-rw-r--    1 ec2-user ec2-user      797 Jun 21 05:14 Jenkinsfile
    drwxrwxrwx 1280 ec2-user ec2-user    40960 Jun 15 17:58 node_modules
    -rw-rw-r--    1 ec2-user ec2-user     3429 Jun 21 05:14 package.json
    -rw-rw-r--    1 ec2-user ec2-user  1070508 Jun 21 05:14 package-lock.json
    drwxrwxrwx    4 ec2-user ec2-user      105 Jun 21 05:14 public
    -rw-rw-r--    1 ec2-user ec2-user     4397 Jun 21 05:14 README.md
    -rw-rw-r--    1 ec2-user ec2-user      285 Jun 21 05:14 serve.json
    drwxrwxrwx    5 ec2-user ec2-user      101 Jun 21 05:14 src
    -rw-rw-r--    1 ec2-user ec2-user     1784 Jun 21 05:14 webpack.config.js
    -rwxrwxrwx    1 root     root       653925 Jun 15 17:56 yarn.lock
    + sudo npm start
    [Pipeline] }
    [Pipeline] // script
    [Pipeline] }
    [Pipeline] // withEnv
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // withEnv
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    Finished: SUCCESS

当我通过登录到 EC2 服务器手动使用相同的命令(sudo npm run start)部署应用程序时,它正在运行并且我看到了输出,但是来自 Jenkins 我遇到了这个问题。

谁能帮忙解决这个问题?

【问题讨论】:

  • 根据您的管道,您正在 Jenkins label 'master' 上执行您的 npm 命令。这是您要启动服务器的地方吗?
  • 您可以检查尝试运行npm start & 命令的用户权限。如果用户说是 jenkins,请检查它是否具有使用 sudo 执行 npm 命令的正确权限。
  • 嗨@ycr 你能再检查一下管道吗?我在部署阶段提到了标签'testnode'......这是我执行npm命令以启动服务器的地方
  • 谢谢@Sourav 的建议,会检查并更新
  • npm start & 你在后台运行你的应用程序,所以你不能直接从npm start & 执行的地方看到应用程序日志。你可以尝试删除&,然后你可以看到app log,但是这样你的Jenkins pipeline 不会结束。

标签: reactjs jenkins build jenkins-pipeline cicd


【解决方案1】:

在 jenkins 管道中,始终使用“run”执行 npm 命令

ex - npm run start / npm run test / npm run lint

【讨论】:

    猜你喜欢
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    相关资源
    最近更新 更多