Answers: <p>Seems like <code>--clean</code> is hardcoded into the MercurialSCM Jenkins plugin.</p>
  
  <p>See OP for the <a href="https://github.com/jenkinsci/mercurial-plugin/blob/5c6297af895dddc2eee75647c9d13786226a38fc/src/main/java/hudson/plugins/mercurial/MercurialSCM.java#L728" rel="nofollow noreferrer">link to the culprit code</a>.</p>
  
  <p>I have opened up a <a href="https://issues.jenkins-ci.org/browse/JENKINS-55870" rel="nofollow noreferrer">ticket on Jenkins jira</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-31T17:18:06.070Z
Answers: 2019-01-31T17:18:06.070Z
Answers: Ziffusion
Body: <p><strong>EDIT:</strong> It seems as if the MercurialSCM plugin hardcodes the <code>update</code> to use the <code>--clean</code> option. See <a href="https://github.com/jenkinsci/mercurial-plugin/blob/5c6297af895dddc2eee75647c9d13786226a38fc/src/main/java/hudson/plugins/mercurial/MercurialSCM.java#L728" rel="nofollow noreferrer">this line</a>. Anyone have any ideas what's the idea?</p>
  
  <p>I have the following checkout step in my Jenkinsfile:</p>
  
  <pre><code>checkout([
          scm: [
              $class: "MercurialSCM",
              source: "ssh://hg@bitbucket.org/xxxxx/${repo}",
              credentialsId: "jenkins",
              revision: params[branch] ? params[branch] : "default",
              subdir: (repo == "f8_root") ? "" : "aarch64/${repo}",
              clean: false,
          ],
          poll: true,
  ])
  </code></pre>
  
  <p>The argument for <code>clean</code> is set to <code>false</code>. But, the plugin still seems to issue an <code>update</code> with the <code>--clean</code> option. From the logs:</p>
  
  <pre><code>[Pipeline] checkout
  [f8_fw] $ hg showconfig paths.default
  [f8_fw] $ hg pull --rev feature/test-framework
  pulling from ssh://hg@bitbucket.org/doblesc/f8_fw
  no changes found
  [f8_fw] $ hg update --clean --rev feature/test-framework
  </code></pre>
  
  <p>How can I fix this?</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-01-30T17:47:59.793Z
Comments: Maybe a dumb question, but have you tried omitting the `clean` parameter altogether?  As far as I can tell, the default is not to do a clean build.  So if you omit `clean`, it should follow the default behavior.  Unfortunately I don't have any mercurial repositories available to test with, so I can't verify this myself.
Comments: jayhendren
Comments: CC BY-SA 4.0
Comments: 2019-01-30T18:01:30.250Z
Comments: Yes, I did. Interestingly, I found that the MercurialSCM hardcodes the `--clean` option for the `update`. See edit to the OP.
Comments: Ziffusion
Comments: CC BY-SA 4.0
Comments: 2019-01-30T19:41:36.227Z
Comments: I suggest filing a [bug report](https://issues.jenkins-ci.org/secure/Dashboard.jspa)
Comments: jayhendren
Tags: <jenkins><jenkins-plugins>
Title: Jenkins: mercurial scm: clean=false is not working as expected
UserDisplayName: Ziffusion
ThreadText: # Jenkins: mercurial scm: clean=false is not working as expected
  
  (Asked by: username_0 on 2019-01-30)
  
  **EDIT:** It seems as if the MercurialSCM plugin hardcodes the `update` to use the `--clean` option. See [this line](https://github.com/jenkinsci/mercurial-plugin/blob/5c6297af895dddc2eee75647c9d13786226a38fc/src/main/java/hudson/plugins/mercurial/MercurialSCM.java#L728). Anyone have any ideas what's the idea?
  
  I have the following checkout step in my Jenkinsfile:
  
  ```
  checkout([
          scm: [
              $class: "MercurialSCM",
              source: "ssh://hg@bitbucket.org/xxxxx/${repo}",
              credentialsId: "jenkins",
              revision: params[branch] ? params[branch] : "default",
              subdir: (repo == "f8_root") ? "" : "aarch64/${repo}",
              clean: false,
          ],
          poll: true,
  ])
  
  ```
  
  The argument for `clean` is set to `false`. But, the plugin still seems to issue an `update` with the `--clean` option. From the logs:
  
  ```
  [Pipeline] checkout
  [f8_fw] $ hg showconfig paths.default
  [f8_fw] $ hg pull --rev feature/test-framework
  pulling from ssh://hg@bitbucket.org/doblesc/f8_fw
  no changes found
  [f8_fw] $ hg update --clean --rev feature/test-framework
  
  ```
  
  How can I fix this?
  
  **Tags:** jenkins, jenkins-plugins
  
  > **Comments:**
  > **username_1**: Maybe a dumb question, but have you tried omitting the `clean` parameter altogether?  As far as I can tell, the default is not to do a clean build.  So if you omit `clean`, it should follow the default behavior.  Unfortunately I don't have any mercurial repositories available to test with, so I can't verify this myself.  
  > **username_0**: Yes, I did. Interestingly, I found that the MercurialSCM hardcodes the `--clean` option for the `update`. See edit to the OP.  
  > **username_1**: I suggest filing a [bug report](https://issues.jenkins-ci.org/secure/Dashboard.jspa)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-01-31. Score: 0 | Accepted answer
  
  Seems like `--clean` is hardcoded into the MercurialSCM Jenkins plugin.
  
  See OP for the [link to the culprit code](https://github.com/jenkinsci/mercurial-plugin/blob/5c6297af895dddc2eee75647c9d13786226a38fc/src/main/java/hudson/plugins/mercurial/MercurialSCM.java#L728).
  
  I have opened up a [ticket on Jenkins jira](https://issues.jenkins-ci.org/browse/JENKINS-55870).
  
  
  ---
  
  