Still failing:
[Commons Updater] Running shell script
+ git clone -b master git@****.com:****/.git
Cloning into 'security-services'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
This happens because the the variable is missing when trying to execute the
shell command:
for (int i = 0; i < repoList.size(); i++) {
def repoName = repoList[i]
sshagent (credentials: ['credential-id']) {
sh '''
git clone -b master
git@****.com:****/${repoName}.git
cd ${repoName}
...
Note how it attempts to clone /.git instead of /the-repo-name.git.
I know that the repoList is occupied with the repo names because if I will
echo it, I see the repo name.
def repoList = ReposToUpdate.tokenize(",");
echo repoList[0]
On Tuesday, August 8, 2017 at 3:54:17 PM UTC+3, mpapo - Michael Pailloncy
wrote:
>
> Oh just realized that this for loop syntax exists even in Groovy :-) (I'm
> used to using *each *instead of for loops)
> But please try using C-style for loop syntax.
>
> 2017-08-08 14:45 GMT+02:00 Michael Pailloncy <[email protected]
> <javascript:>>:
>
>> This syntax doesn't exist in Groovy : *for (String repoName : repoList)
>> { ... }*
>> The direct equivalent is : *for (String repoName in repoList) { ... }*
>>
>> However, it's better to use the C-style for loop syntax when using
>> pipeline (that's why I've used it in my previous example) :
>>
>> for (int i = 0; i < moduleList.size(); i++) {
>> def moduleName = moduleList[i]
>> ...
>> }
>>
>> See
>> https://github.com/jenkinsci/pipeline-examples/blob/master/docs/BEST_PRACTICES.md#groovy-gotchas
>>
>> Cheers
>>
>> 2017-08-08 14:31 GMT+02:00 Idan Adar <[email protected] <javascript:>>:
>>
>>> I've made some changes and now I'm getting:
>>>
>>> java.lang.NullPointerException: Cannot get property '$repoName' on null
>>> object
>>>
>>>
>>>
>>> def repoList = ReposToUpdate.tokenize(",");
>>> def moduleList = npmDependencies.tokenize(",");
>>>
>>> pipeline {
>>> agent {
>>> label '****'
>>> }
>>>
>>> stages {
>>> stage ("Update package.json") {
>>> steps {
>>> script {
>>> for (String repoName : repoList) {
>>> sshagent (credentials: ['****']) {
>>> sh '''
>>> git clone -b master
>>> git@****.com:****/${repoName}.git
>>> cd ${repoName}
>>> stat -t . > folderStat1.txt
>>> '''
>>>
>>> for (String moduleName : moduleList) {
>>> sh '''
>>> cd ${repoName}
>>> ncu -u -f "${moduleName}"
>>> stat -t . > folderStat2.txt
>>> '''
>>> }
>>>
>>> def folderStat1 = readFile('folderStat1.txt').trim()
>>> def folderStat2 = readFile('folderStat2.txt').trim()
>>>
>>> if (folderStat1 == folderStat2) {
>>> slackSend (
>>> color: '#199515',
>>> message: "$JOB_NAME: <$BUILD_URL|Build
>>> #$BUILD_NUMBER> ${repoName}: Common code dependencies match the latest
>>> package versions."
>>> )
>>> }
>>> else {
>>> sh '''
>>> cd ${repoName}
>>>
>>> git config --global user.name "****"
>>> git config --global user.email ****
>>> git commit -am 'Bump common packages version
>>> number [ci skip]'
>>> git push origin master
>>>
>>> cd ..
>>> rm -rf ${repoName}
>>> '''
>>>
>>> slackSend (
>>> color: '#199515',
>>> message: "$JOB_NAME: <$BUILD_URL|Build
>>> #$BUILD_NUMBER> ${repoName}: Common code dependencies successfully updated
>>> to the latest package versions."
>>> )
>>> }
>>> }
>>> }
>>> }
>>> }
>>> }
>>> }
>>>
>>> post {
>>> failure {
>>> slackSend (
>>> color: '#F01717',
>>> message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER>,
>>> Update failed. Review the build logs."
>>> )
>>> }
>>> }
>>> }
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Jenkins Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected] <javascript:>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/jenkinsci-users/54962dc1-e80e-4ce3-8583-652a1fd714fe%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/jenkinsci-users/54962dc1-e80e-4ce3-8583-652a1fd714fe%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/0ef4f753-7026-4794-a162-d882d8b2701e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.