is it possible to set sort of a project-variable in rundeck?
I am organizing jobs in projects, but the jobs are mostly the same and use the same values over and over again. If I could set variables per project, I could just copy jobs from project to project without having to adapt the same parameters over and over again...
like... path=/path/to/project
and use the variable path in jobs
Thanks, regards
Jochen
You can define a global variable for that. You can define it on framework.properties file like framework.globals.myvar=myvalue or at project level (project.properties config) like project.globals.myvar=myvalue, to access it just use ${globals.myvar} for steps, #globals.myvar# for inline-scripts or $RD_GLOBALS_MYVAR for scripts.
UPDATE:
In Rundeck 3.1/3.2/3.3/4.X the "project.properties" isn't a "file", is a config reachable/editable following this.
Related
I have an Nx monorepo project set up. I want to set some environment variables to use throughout my app. I'm looking for a solution where I can define a value for these variables during the release process to each environment (QA, Test, Dev).
Example:
NX_API_URL is my environment variable in my .env file.
If I release to QA env the variable should be NX_API_URL=api-url-qa.com.
If I release to Test env the variable should be NX_API_URL=api-url-test.com
I have found solutions during the build process but that's not going to work, it needs to be at the release phase. How can I accomplish this?
If the file that you'd like to modify during the deployment process is either XML or JSON you can define the URLs as tokens and use standard 'FileTransform' task to replace them: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/file-transform-v2?view=azure-pipelines
For more details regarding file transformation please refer to documentation: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops&tabs=Classic
If none of the links above will help you with this, then I'd suggest to create PS script to do whatever modifications are required, like adding a line after specific line definition: https://social.technet.microsoft.com/Forums/office/en-US/fabc9790-0ffe-43b2-9d6b-bc483cd28bb6/add-line-to-a-text-file-just-after-a-specific-line-with-powershell?forum=winserverpowershell
Is there a way to create global environment variables for groups in Rundeck in the same way we can create one for Projects.
For eg : project.globals.version = 123
You can create a "really globally" variables from framework.properties file using framework.global.myvar=myvalue and from project.properties file using project.globals.myvar=another_value (for each project).
You've more info here.
I want a Rundeck job to download a file over HTTP on the Rundeck server, copy that file over to other nodes, do work on that file on the nodes, and then delete the file from the Rundeck server.
So far, I've got three jobs:
Get File: has "url" and "localfile" options
Delete File: has "localfile" option
Main Job: has "url" option.
I have Main Job doing these steps:
Workflow step: Call "Get File" job with -url ${option.url} -localfile /tmp/tempfile.${job.execid}
Node step: Copy file to node with SourcePath=/tmp/tempfile.${job.execid} and DestinationPath=/tmp/tempfile.${job.execid}
Node step: Run inline script on node
Workflow step: Call "Delete File" job with -localfile /tmp/tempfile.${job.execid}
Is there some way I can define a variable or an option for "localfile" for reuse in all my steps rather than having to put '/tmp/tempfile.${job.execid} in three or four places? If I want to redefine where this tempfile is later, it would be much easier to have one place to change it. I have tried defining an option built from other options in "Main Job", but it didn't work.
You can create an environment variable for it, but you still need to pass this variable to next job.
Context Variable Usage
Make sure you Configuring remote machine for SSH
I would like to capture the output of some variables to be used elsewhere in the job using Jenkins Powershell plugin.
Is this possible?
My goal is to build the latest tag somehow and the powershell script was meant to achieve that, outputing to a text file would not help and environment variables can't be used because the process is seemingly forked unfortunately
Besides EnvInject the another common approach for sharing data between build steps is to store results in files located at job workspace.
The idea is to skip using environment variables altogether and just write/read files.
It seems that the only solution is to combine with EnvInject plugin. You can create a text file with key value pairs from powershell then export them into the build using the EnvInject plugin.
You should make the workspace persistant for this job , then you can save the data you need to file. Other jobs can then access this persistant workspace or use it as their own as long as they are on the same node.
Another option would be to use jenkins built in artifact retention, at the end of the jobs configure page there will be an option to retain files specified by a match (e.g *.xml or last_build_number). These are then given a specific address that can be used by other jobs regardless of which node they are on , the address can be on the master or the node IIRC.
For the simple case of wanting to read a single object from Powershell you can convert it to a JSON string in Powershell and then convert it back in Groovy. Here's an example:
def pathsJSON = powershell(returnStdout: true, script: "ConvertTo-Json ((Get-ChildItem -Path *.txt) | select -Property Name)");
def paths = [];
if(pathsJSON != '') {
paths = readJSON text: pathsJSON
}
I'm new to Chef and seeking help here. I'm looking into using Chef to deploy our builds to Chef node servers (Windows Server 2012 machines). I have a cookbook called copy_builds that goes out to a central repository and selects the build we want to deploy and copies it out to the node server. The recipe I have contains basic steps that perform the copy steps, and this recipe could be used for all builds we want to deploy except for one thing: the build name.
Here is an example of the recipe:
powershell_script 'Copy build files' do
code '
$Project = "Dev3_SomeCoolBuild"
net use "\\\\server\\build_share\\drop\\$Project"
$BuildNum = GC "\\\\server\\build_share\\drop\\$Project\\buildlabel.txt"
robocopy \\\\server\\build_share\\drop\\$Project\\bin W:\\binroot\\$BuildNum'
end
As you can see, the variable $Project contains the name of the build in this recipe. If we have 100 different builds, all with different names, then what is the best way to handle this without creating 100 different recipes for my copy_builds cookbook?
BTW: this is how I'm currently calling Chef to deploy, which is in a PowerShell script that's external to Chef:
knife node run_list set $Node "recipe[copy_builds::$ProjectName],recipe[install_build]"
This command (from the external PowerShell script) contains the project/build name info within it's own $ProjectName variable. In this case $ProjectName contains the value of 'Dev3_SomeCoolBuild', to reference the recipe Dev3_SomeCoolBuild.rb.
What I'd like is have just one default recipe under copy_builds cookbook, and pass in the build/project name. Is this possible? And what is the best way to do it? I've read about data bags, attributes, and providers, but not sure if they would work for what I want.
Please advise.
Thanks,
Keith
The best approach for you is likely to use a single recipe that gets a list of projects to deploy from a databag or node attributes (or both). So basically take what you have now and put it in a loop, and then use either roles to set node attributes or put the project mapping into a databag item.
I ended up using attributes here to solve my problem. I updated my script to write the build name to the attributes/default.rb file for the copy_builds recipe and upload the cookbook to Chef each time a deployment is run.
My recipe now includes a call to the attributes file to get the build name, like so:
powershell_script 'Copy build files' do
code <<-EOH
$BuildNum = GC \\\\hqfas302002c\\build_share\\drop\\"#{node['copy_builds']['build']}"\\buildlabel.txt
robocopy \\\\hqfas302002c\\build_share\\drop\\"#{node['copy_builds']['build']}"\\webbin W:\\binroot\\$BuildNum /E
EOH
end
And now my call to Chef looks like this:
knife node run_list set $Node "recipe[copy_builds],recipe[install_build]"