Answers: <p>This article very clearly explains how to deploy a nodejs app using Jenkins:</p>
  
  <p><a href="https://blog.couchbase.com/create-continuous-deployment-pipeline-nodejs-jenkins/" rel="nofollow noreferrer">https://blog.couchbase.com/create-continuous-deployment-pipeline-nodejs-jenkins/</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2019-06-20T09:21:56.187Z
Answers: 2019-06-20T09:21:56.187Z
Answers: Subhash
Answers: <p>delete your job, create a new one, add a step clean workspace as the first step of your job. with pipelines it is <code>cleanWs()</code>. see plugin doc here: <a href="https://wiki.jenkins.io/display/JENKINS/Workspace+Cleanup+Plugin" rel="nofollow noreferrer">https://wiki.jenkins.io/display/JENKINS/Workspace+Cleanup+Plugin</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-23T21:30:18.020Z
Answers: 2019-04-23T21:30:18.020Z
Answers: fredericrous
Answers: <p>You have a GIT permissions issue (you cannot write to files and or directory):</p>
  
  <p><a href="https://stackoverflow.com/questions/11774397/git-push-error-unable-to-unlink-old-permission-denied">https://stackoverflow.com/questions/11774397/git-push-error-unable-to-unlink-old-permission-denied</a></p>
  
  <pre><code>stderr:
  error: unable to unlink old 'node_modules/express-session/HISTORY.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/LICENSE': Permission denied
  error: unable to unlink old 'node_modules/express-session/README.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/index.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/package.json': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/cookie.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/memory.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/session.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/store.js': Permission denied
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-23T10:45:03.770Z
Answers: Thought I didn't assume the permission problem because when I checked the webhook in Github, showed me verified.
Answers: Chachatonel Hashimotto
Answers: CC BY-SA 4.0
Answers: 2019-04-23T10:48:49.233Z
Answers: The problem had been happening after a Jenkins job runs few times.
Answers: Chachatonel Hashimotto
Answers: CC BY-SA 4.0
Answers: 2019-04-17T19:16:53.993Z
Answers: 2019-04-17T19:16:53.993Z
Answers: casey vega
Body: <p>I'm a very beginner in Jenkins and afraid that I ask you something not clear with a weird question.</p>
  
  <p>I'd like to deploy my simple node app server to Ubuntu via Jenkins. </p>
  
  <p>I tried to write a command in Build at a Job as below :</p>
  
  <pre><code>./script/deploy.sh
  </code></pre>
  
  <p>deploy.sh file is here.</p>
  
  <pre><code>#!/bin/sh
  EOF
   npm install
   pm2 restart app.js --name="myApp"
   exit
  EOF
  </code></pre>
  
  <p>When I run a build, it stucked with error as </p>
  
  <pre><code>FATAL: Could not checkout 0d563b394d506e8450833e9b36d7a7b44834df39
  </code></pre>
  
  <p>The Full log of Error.</p>
  
  <pre><code> &gt; git checkout -f 0d563b394d506e8450833e9b36d7a7b44834df39
  FATAL: Could not checkout 0d563b394d506e8450833e9b36d7a7b44834df39
  hudson.plugins.git.GitException: Command "git checkout -f 0d563b394d506e8450833e9b36d7a7b44834df39" returned status code 1:
  stdout: 
  stderr: error: unable to unlink old 'node_modules/express-session/HISTORY.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/LICENSE': Permission denied
  error: unable to unlink old 'node_modules/express-session/README.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/index.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/package.json': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/cookie.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/memory.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/session.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/store.js': Permission denied
  HEAD is now at 0d563b3 commit
  
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$900(CliGitAPIImpl.java:72)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2341)
  Caused: hudson.plugins.git.GitException: Could not checkout 0d563b394d506e8450833e9b36d7a7b44834df39
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2365)
      at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1242)
      at hudson.scm.SCM.checkout(SCM.java:504)
      at hudson.model.AbstractProject.checkout(AbstractProject.java:1208)
      at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)
      at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
      at hudson.model.Run.execute(Run.java:1816)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:97)
      at hudson.model.Executor.run(Executor.java:429)
  Finished: FAILURE
  </code></pre>
  
  <p>My questions :</p>
  
  <p><strong>1. How to deploy a node app to ubuntu via Jenkins.</strong></p>
  
  <ul>
  <li>Is my way right? or another way is better?</li>
  </ul>
  
  <p><strong>2. What error is it as following the log.</strong></p>
  
Tags: <jenkins><continuous-integration><deployment><continuous-delivery>
Title: How to deploy Node app via Jenkins to Ubuntu(18.04)?
UserDisplayName: Chachatonel Hashimotto
ThreadText: # How to deploy Node app via Jenkins to Ubuntu(18.04)?
  
  (Asked by: username_0 on 2019-04-17)
  
  I'm a very beginner in Jenkins and afraid that I ask you something not clear with a weird question.
  
  I'd like to deploy my simple node app server to Ubuntu via Jenkins.
  
  I tried to write a command in Build at a Job as below :
  
  ```
  ./script/deploy.sh
  
  ```
  
  deploy.sh file is here.
  
  ```
  #!/bin/sh
  EOF
   npm install
   pm2 restart app.js --name="myApp"
   exit
  EOF
  
  ```
  
  When I run a build, it stucked with error as
  
  ```
  FATAL: Could not checkout 0d563b394d506e8450833e9b36d7a7b44834df39
  
  ```
  
  The Full log of Error.
  
  ```
   > git checkout -f 0d563b394d506e8450833e9b36d7a7b44834df39
  FATAL: Could not checkout 0d563b394d506e8450833e9b36d7a7b44834df39
  hudson.plugins.git.GitException: Command "git checkout -f 0d563b394d506e8450833e9b36d7a7b44834df39" returned status code 1:
  stdout: 
  stderr: error: unable to unlink old 'node_modules/express-session/HISTORY.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/LICENSE': Permission denied
  error: unable to unlink old 'node_modules/express-session/README.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/index.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/package.json': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/cookie.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/memory.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/session.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/store.js': Permission denied
  HEAD is now at 0d563b3 commit
  
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$900(CliGitAPIImpl.java:72)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2341)
  Caused: hudson.plugins.git.GitException: Could not checkout 0d563b394d506e8450833e9b36d7a7b44834df39
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2365)
      at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1242)
      at hudson.scm.SCM.checkout(SCM.java:504)
      at hudson.model.AbstractProject.checkout(AbstractProject.java:1208)
      at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)
      at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
      at hudson.model.Run.execute(Run.java:1816)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:97)
      at hudson.model.Executor.run(Executor.java:429)
  Finished: FAILURE
  
  ```
  
  My questions :
  
  **1. How to deploy a node app to ubuntu via Jenkins.**
  
  * Is my way right? or another way is better?
  
  **2. What error is it as following the log.**
  
  **Tags:** jenkins, continuous-integration, deployment, continuous-delivery
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2019-06-20. Score: 2
  
  This article very clearly explains how to deploy a nodejs app using Jenkins:
  
  <https://blog.couchbase.com/create-continuous-deployment-pipeline-nodejs-jenkins/>
  
  
  ---
  
  ### Answer by username_2 on 2019-04-23. Score: 1
  
  delete your job, create a new one, add a step clean workspace as the first step of your job. with pipelines it is `cleanWs()`. see plugin doc here: <https://wiki.jenkins.io/display/JENKINS/Workspace+Cleanup+Plugin>
  
  
  ---
  
  ### Answer by username_3 on 2019-04-17. Score: 0
  
  You have a GIT permissions issue (you cannot write to files and or directory):
  
  <https://stackoverflow.com/questions/11774397/git-push-error-unable-to-unlink-old-permission-denied>
  
  ```
  stderr:
  error: unable to unlink old 'node_modules/express-session/HISTORY.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/LICENSE': Permission denied
  error: unable to unlink old 'node_modules/express-session/README.md': Permission denied
  error: unable to unlink old 'node_modules/express-session/index.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/package.json': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/cookie.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/memory.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/session.js': Permission denied
  error: unable to unlink old 'node_modules/express-session/session/store.js': Permission denied
  
  ```
  
  > **Comments:**
  > **username_0**: Thought I didn't assume the permission problem because when I checked the webhook in Github, showed me verified.  
  > **username_0**: The problem had been happening after a Jenkins job runs few times.  
  
  ---
  
  