I have a teamcity plan which includes two steps, and I need to store the first step script return value in order to pass it to the second step. The problem is that the [python] script is run as follows:
pipenv run python my_script.py --env_url %env_url%
And even when I know that I can store return values using ##teamcity messages, I don't know how to save the return value of my_script.py due to pipenv run
Any suggestions?
Thanks!
In the same situation, I've just saved the information into a JSON file and read this file in the next step.
Related
I would like to run a command in my pipeline and then save the result in a variable to be used later on in the pipeline. The command I want to run is
gh release view | head -n 1 | cut -f 1
I can log into Github and everything else, so that is not a problem. My only issue is saving the result to a variable and using that variable.
How can I do this?
Unfortunately not. You must write the contents of the variable to file and use inputs and outputs to communicate between tasks. If you need to use the output between jobs, you'll also need a resource as described in the excerpt from https://docs.concourse.farm/power-tutorial/00-core-concepts
When inputs are passed between steps within a job they can remain just
that: inputs/outputs. For passing inputs/outputs between jobs, you
must use resources. A resource is an input/output set whose state is
retrieved/stored externally by a job, e.g. a git repo or an S3 object.
Of course, once a task receives an input from the previous task, it can then be read into a variable.
I am stuck with a problem that I have a update.sh file where I want to replace the word release in update.sh file with develop but that is to be done dynamically. I also have a package.json where there is a script called "update: "./bin/update.sh". This is what I need to change wherein I need to pass a parameter in the update script like "update: "./bin/update.sh --develop" such that whenever I run npm run update it replaces all occurences of word release with develop and run to continue with ./bin/update.sh
Is there any way to do it?
Thanks in advance. Please help me, I am being stuck on this since 3 days for now.
I have a variable $svn_tag in a Jenkins job.
Its value is branches/sprint-77.
I want the output branches-sprint-77, but I didn't get any output.
I tried these two methods:
$svn_tag|tr "/" -
${svn_tag////-}
It is giving output in bash script, but it is not working in the Jenkins job.
What am I doing wrong?
Your first approach does not make sense, not the least because you try to run `$svn_tagĀ“ as a command. Your second approach works for me:
svn_tag=branches/sprint-77
echo ${svn_tag////-}
prints branches-sprint-77.
For the safe side, you could also check your bash version, by doing a
echo bash=$BASH_VERSION
though I don't think that this feature is version-dependent. Mine is 4.4.12(3)-release.
Use code like below
${svn_tag.replaceAll('/', '-')}
I'm looking for a way to use an output from shell as a jenkins parameter but in pipeline, don't want to use any of UI plugins.
For example I want to use output from command
ls /home
as a choice parameter (so I would be able to choose users from the list), is it possible to do something like that?
It must be done in pipeline, I'm not looking for some plugins which allow you to do something like that, but you need to do all in UI, if plugin support pipelines then it's also ok.
For a pipeline to run, its parameters need to be completely defined before the pipeline is started.
For the pipeline to parse the output of ls /home, it needs to run and allocate a node and a workspace, which can only happen after the pipeline is started.
So you are in a kind of a chicken-and-egg problem, where you need to run some code before you start a pipeline, but you can't run pipeline before you run that code.
So your issue boils down to "How can I run some arbitrary Groovy script before I start my pipeline?"
There are two options for this:
ActiveChoice plugin allows you to define a parameter that returns a script. Jenkins will then run the script (don't forget to approve it) in order to show you your "Build with parameters" page. Debugging this is notoriously hard, but this can go to great lengths.
Alternatively, you may want to run a scripted pipeline before you run the Declarative (main) one, as outlined e.g. in this answer. This may look a bit like this:
def my_choices_list = []
node('master') {
stage('prepare choices') {
// read the folder contents
def my_choices = sh script: "ls -l /home", returnStdout:true
// make a list out of it - I haven't tested this!
my_choices_list = my_choices.trim().split("\n")
}
}
pipeline {
parameters {
choiceParam('OPTION', my_choices_list)
I've pulled a few scripts into Jenkins for a proof of concept and think I'd like to move that direction for all of our scripts. Right now I keep an environment.rb file with my code (watir-webdriver, cucumber) which tells the script which environment we're testing and which browser to use (global variables). Jenkins fires off the script using rake.
I'd love to let the user choose the environment and browser through Jenkins 'choice' variable or similar, and then pass that to the script. While I see the framework in that for Jenkins and set up a choice list for environment, I'm having trouble determining what the next step is.
I could write to environment.rb, I could pass a variable to rake - I have many options for how to pass the information, I just need some assistance finding the first step to find the Jenkins way of accomplishing them. Google results and previous Stack questions weren't what I was looking for.
Thanks
Sure. Give the user either a text entry field a dropdown after telling Jenkins that this is a parameterized build. You'll give them a name, something like BuildEnvironment. Then when you call the build, you can pass these from the environment variables. For example, if you were using ANT, you'd add a line to the parameters that said environment = ${MyEnvironment} Jenkins will then pass the value along for your build tool to use.
There is a way to pass Jenkins Environment Variable to Ruby script. Please see the following example:
workspace_path = `echo $WORKSPACE`.strip # note the use of backticks
puts workspace_path
In the "echo $WORKSPACE".strip # the code work only if you replace quotes with backticks
This code example works in Jenkins on a Linux system.