LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-10-2019, 08:28 AM   #16
flukeyLinux
Member
 
Registered: Sep 2012
Location: Ireland
Distribution: Ubuntu redhat.
Posts: 31

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by Firerat View Post
Tried this but no joy either. The echo comes back blank.
post the whole section of code
even if ( I assume java now ) didn't concatenate +teamname+ into the sting the echo should have -REL[/QUOTE]

Code:
import groovy.json.*
import jenkins.model.*
import com.cloudbees.opscenter.plugins.updatecenter.*
import com.cloudbees.plugins.updatecenter.sources.*


pipeline {
  agent any
  parameters {
    string(name: 'Appid',
      defaultValue: '',
      description: 'Enter Application Id for your application')
    string(name: 'DisplayName',
       defaultValue: '',
       description: 'Enter unique displayName for your team')

  }
  stages {


    stage("Validate Inputs"){
        steps{
            script{

            loweritam = "${params.Appid}".trim().toLowerCase()

                }
            }

    }


    stage("Create Team"){
        steps{
            script {

                    def jsonfile = readJSON file: 'team.json'
                    def header = jsonfile.data.members

                    jsonfile.data.displayName = "${params.DisplayName}".inspect()

                    jsonfile.data.icon.name = "${params.Appid}".inspect()

                    jsonfile.data.name = "${params.Appid}".inspect()

                    header.id = "azg${params.Appid}Admin_RESTR".inspect()

                    writeJSON file: 'output.json', json: jsonfile

                    println("Team creation json based on user provided details is as below")
                    sh "cat output.json"

                    println("Creating Team for ${params.Appid}")
                    sh "wget https://jenkinscore.com/cjoc/jnlpJars/jenkins-cli.jar"
                    sh "chmod 755 jenkins-cli.jar"
                    sh "chmod 755 cli"

                    sh "./cli teams ${params.Appid} --put < output.json"

                    println("Your Team creation is in progress ")
           
                    sh "sleep 150"
                    def teamname="${loweritam}"
                    sh '''
                      loweritamREL=$(cat rel)
                      loweritam=${loweritamREL::-4}
                      sed -i "s/placeteamhere/$loweritamREL/g" templates/config.xml
                      /bin/cat templates/config.xml | ./cli -s https://jenkinscore.com/teams-$loweritam/ create-job $loweritamREL
                      '''

                    sh '''
                      echo '''+teamname+'-REL'''' > dev
                      loweritamDEV=$(cat dev)
                      sed -i "s/$loweritamREL/$loweritamDEV/g" templates/config.xml
                      /bin/cat templates/config.xml | ./cli -s https://jenkinscore.com/teams-$loweritam/ create-job $loweritamDEV
                      '''
                    }

             }
          }

      stage("Assign Update Center"){
...
 
Old 09-10-2019, 08:39 AM   #17
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,995

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
ok, take a look at this gist

https://gist.github.com/Faheetah/e11...81616e41279ef4

looks like that will help
 
1 members found this post helpful.
Old 09-10-2019, 09:37 AM   #18
flukeyLinux
Member
 
Registered: Sep 2012
Location: Ireland
Distribution: Ubuntu redhat.
Posts: 31

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
ok, take a look at this gist

https://gist.github.com/Faheetah/e11...81616e41279ef4

looks like that will help
that page is a little helpful but still. I really do not understand what is wrong.

This works:
Code:
sh """
                        echo ${loweritam}-REL
                    """
This works:
Code:
sh "echo \"${teamname}\"-REL"
This does not work:
Code:
sh '''
                      loweritamREL=$(echo ${loweritam}-REL)
                       '''
This does not work:
Code:
sh "loweritamREL=$(echo \"${teamname}\"-REL)"
This does not work:
Code:
sh "echo \"${teamname}\"-REL > rel"
these are essentially exactly the same commands but I am trying to store them somehow.
 
Old 09-10-2019, 10:47 AM   #19
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,995

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
ok,
I'm going to go back to your sh script
and pretend that groovy is not involved at all

Code:
#!/bin/sh
loweritamREL=$(cat rel) # var is contents of a file
loweritam=${loweritamREL::-4} # it looks like you are using bash here
# what do you want ? the last 4? that is first 4
# if were were in bash
# loweritam=${loweritamREL:(-4)}
sed -i "s/placeteamhere/$loweritamREL/g" templates/config.xml
/bin/cat templates/config.xml | ./cli -s https://jenkinscore.com/teams-$loweritam/ create-job $loweritamREL
if looks like you are executing bash with sh
but the bash you are using is to hack around dumping $teamname into a file
after populating that with $loweritam

Code:
sh -c '''
echo "sed -i \"s/placeteamhere/'${loweritam}${appteam}'/g\" templates/config.xml
< templates/config.xml ./cli -s https://jenkinscore.com/teams-'${loweritam}'/ create-job '${appteam}'" > debug.me
'''
I escaped the " with \
only so they go into the debug.me file

tbh, I have no idea where ${appteam} comes from, I think it is -REL.. but I've lost track with all the hack vars

Last edited by Firerat; 09-10-2019 at 10:50 AM. Reason: tested on bash, need sh -c
 
Old 09-10-2019, 10:51 AM   #20
flukeyLinux
Member
 
Registered: Sep 2012
Location: Ireland
Distribution: Ubuntu redhat.
Posts: 31

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
ok,
I'm going to go back to your sh script
and pretend that groovy is not involved at all

Code:
#!/bin/sh
loweritamREL=$(cat rel) # var is contents of a file
loweritam=${loweritamREL::-4} # it looks like you are using bash here
# what do you want ? the last 4? that is first 4
# if were were in bash
# loweritam=${loweritamREL:(-4)}
sed -i "s/placeteamhere/$loweritamREL/g" templates/config.xml
/bin/cat templates/config.xml | ./cli -s https://jenkinscore.com/teams-$loweritam/ create-job $loweritamREL
if looks like you are executing bash with sh
but the bash you are using is to hack around dumping $teamname into a file
after populating that with $loweritam

Code:
sh '''
echo "sed -i \"s/placeteamhere/'${loweritam}${appteam}'/g\" templates/config.xml
< templates/config.xml ./cli -s https://jenkinscore.com/teams-'${loweritam}'/ create-job '${appteam}'" > debug.me
'''
I escaped the " with \
only so they go into the debug.me file

tbh, I have no idea where ${appteam} comes from, I think it is -REL.. but I've lost track with all the hack vars

Ok I've got it. and it's embarrassing but I knew it would be

Single quotes = no
Double quotes = yes

Code:
                    sh "sed -i s/placeteamhere/${loweritam}-REL/g templates/config.xml"
                    sh "/bin/cat templates/config.xml | ./cli -s https://jenkinscore.com/teams-${loweritam}/ create-job ${loweritam}-REL"
                    sh "sed -i s/${loweritam}-REL/${loweritam}-DEV/g templates/config.xml"
                    sh "/bin/cat templates/config.xml | ./cli -s https://jenkinscore.com/teams-${loweritam}/ create-job ${loweritam}-DEV"
these 4 lines do what I was trying to do all along. create two folders under a jenkins team and add the display name (sed command). I got rid of the lines that were creating extra variables and just used the groovy ones in curly brackets and double quotes.

thanks all for the help!
 
Old 09-10-2019, 01:23 PM   #21
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,635

Rep: Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205
Quote:
Originally Posted by flukeyLinux View Post
Single quotes = no
Double quotes = yes
Yes:
Single quotes = shell does not interpolate variables
Double quotes = shell does interpolate variables
 
  


Reply

Tags
jenkins, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Escaping a variable in Groovy to show the ascii character in println? edomingox Programming 1 04-25-2009 07:24 PM
running Bash commands in Groovy or Beanshell scripts edomingox Programming 6 04-24-2009 07:07 AM
LXer: Google Mashups get their Groovy on LXer Syndicated Linux News 0 03-29-2008 04:30 AM
LXer: Reduce Code Noise with Groovy LXer Syndicated Linux News 0 09-21-2006 06:54 AM
Terratec 6Fire and Groovy DeadRat _Mhz Linux - Hardware 0 10-18-2003 05:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration