-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #546 from jenkinsci/nre/master/immutable-params-de…
…clarative Make params immutable for declarative piplines
- Loading branch information
Showing
6 changed files
with
53 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/groovy/com/lesfurets/jenkins/TestDeclarativeImmutableParams.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.lesfurets.jenkins | ||
|
||
import com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
import static org.junit.Assert.assertEquals | ||
|
||
class TestDeclarativeImmutableParams extends DeclarativePipelineTest { | ||
|
||
@Override | ||
@Before | ||
void setUp() throws Exception { | ||
scriptRoots += 'src/test/jenkins' | ||
|
||
super.setUp() | ||
} | ||
|
||
@Test(expected = UnsupportedOperationException) | ||
void "test immutable params in declarative pipeline"() { | ||
runScript("job/library/test_params_immutable_declarative.jenkins") | ||
assertEquals('original', binding.params['new'].toString()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/jenkins/job/library/test_params_immutable_declarative.jenkins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pipeline { | ||
parameters { | ||
string( | ||
name: 'TEST_STRING', | ||
defaultValue: 'original' | ||
) | ||
} | ||
|
||
stages { | ||
stage('Test declarative parameters') { | ||
steps { | ||
script { | ||
params.TEST_STRING = 'new' | ||
} | ||
} | ||
} | ||
} | ||
} |