I have several k8s_object rules in my project and I supply each of them with the same cluster name like this:
k8s_object(
name = "k8s_service",
kind = "service",
cluster = "gke_cents-ideas_europe-west3-b_cents-ideas",
template = ":gateway.service.yaml",
)
So whenever I want to change the cluster name, I have to change it in many different places.
Goal
I would prefer to set the cluster name in a .env file like this:
KUBERNETES_CLUSTER=my-cluster-name
and let Bazel automatically pick up this value.
https://docs.bazel.build/versions/2.0.0/skylark/tutorial-sharing-variables.html
Create a .bzl file in which you can declare a variable. Import this bzl file in all BUILD files referencing the variable.
Related
I'm creating a custom Fluent-Bit image and I want a "generic" configuration file that can work on multiple cases, i.e.: it should work with a forward input sometimes and with tail input some other times.
I thought about using environment variables so to only have one input but it seems we cannot set variables in the key part only on the value side (see following code).
When I set the corresponding environment variables in a docker-entrypoint file with corresponding conditions
export INPUT_PATH="/myLogPath"
export INPUT_PATH_TYPE="path"
export INPUT_NAME="tail"
[INPUT]
Name ${INPUT_NAME}
${INPUT_PATH_TYPE} ${INPUT_PATH}
This is the error message I got
[error] [config] tail: unknown configuration property '${INPUT_PATH_TYPE}'. The following properties are allowed: path, exclude_path, key, read_from_head, refresh_interval, watcher_interval, rotate_wait, docker_mode, docker_mode_flush, docker_mode_parser, path_key, ignore_older, buffer_chunk_size, buffer_max_size, skip_long_lines, exit_on_eof, parser, tag_regex, db, db.sync, db.locking, multiline, multiline_flush, parser_firstline, and parser_.
I'm looking for a way to make it dynamic so either to have a single file with dynamic configuration or multiple files which can be included dynamically (#Include requires a static filepath from what I've seen).
EDIT: the only option I see is to have multiple input files (for each use case) and call it dynamically when starting fluent-bit in the docker-entrypoint file
I use a docker-entrypoint and split the input, filters to different files and then depending of the environment variables in the entrypoint I create a symbolic link to the corresponding file
Im using Extended Choice Parameter in Jenkins.
I want to add a drop down parameter in the job and display all folder names within the given directory using a groovy script
how can i do that ?
You can use the following groovy script in the extended choice parameter to list all folders under a given folder (You will probably require an admin approval to run this script):
import groovy.io.FileType
def list = []
def dir = new File("/var/lib/jenkins/workspace")
dir.eachFileRecurse (FileType.DIRECTORIES) { file ->
list << file
}
return list
However, an easier option will be to use the Filesystem List Parameter Plugin.
The plugin lists file, directory or symlink names of a defined directory and exposes them as selection options for the parameter.
It also supports include/exclude patterns and execution on different nodes .
I am trying to build a Docker image with this code:
container_image(
name = "docker_image",
base = "#java_base//image",
files = [":executable_deploy.jar"],
cmd = ["java", "-jar", "executable_deploy.jar"],
env = { "VERSION" : "$(VERSION)" }
)
I want to pass a variable to the target built so it can be replaced in $(VERSION). Is this possible?
I have tried with VERSION=1.0.0 bazel build :docker_image, but I get an error:
$(VERSION) not defined.
How can I pass that variable?
According docs:
The values of this field (env) support make variables (e.g., $(FOO)) and
stamp variables; keys support make variables as well.
But I don't understand exactly what that means.
Those variables can be set via the --define flag.
There is a section on the rules_docker page about stamping which covers this.
Essentially you can do something like:
bazel build --define=VERSION=1.0.0 //:docker_image
It is also possible to source these key / value pairs from the stable-status.txt and volatile-status.txt files. The user manual page for bazel shows how to use these files, and the use of the --workspace_status_command to populate them.
For setting defaults, you could use a .bazelrc file, with something like the following as the contents:
build --define=VERSION=0.0.0-PLACEHOLDER
The flags passed on the command line will take precedence over those in the .bazelrc file.
It's worth mentioning, that changing define values will cause bazel to analyze everything again, which depending on the graph may take some time, but only affected actions will be executed.
I would like to know if there is an option to pass the value from a file to one of the Jenkins parameters. For eg : I have a property file called config.properties and I would like to pass the value of a field called projectName to a Jenkins parameter called Project. How can I do this ?
Use Extended Choice Parameter Plugin - it allows you to define a property file and and a key within the file to use. The plugin expects comma-separated values to allow the user to choose one but if there's only one value - it will be chosen by default.
Add the Plugin Extended choice Parameter as stated by antweisis
Need a Property files which means the file with the content in following format Eg: dates=21012,2013,2014,2015
I have added the Image with how I have Configured the jobs as shown in the image bellow.
To dynamically add the content to a property file create a script and run it as cron job or run the job that will populate the file first.
Where,
Delimiter = comma as we have comma separated the values
Propertyfile = path to the files
Propertykey = the key we have used for our example we have used dates
This will successfully create a drop down from the content of the files.
In my Config.groovy i put line:
grails.config.locations = [ "classpath:app-config.properties"]
where I set definition for datasource. File looks like:
dataSource.url=jdbc:mysql://host/instance
dataSource.username=u
dataSource.password=p
and it properly replace properties from DataSource.groovy.
Problem is that it replace configuration for every environment, but i need separate config for dev, test and production. Trying to put into file different entries like:
environments.development.dataSource.url=jdbc:mysql://host/dev
...
environments.production.dataSource.url=jdbc:mysql://host/prod
...
ends with default data sources properties defined in DataSource.groovy. How to make one property file to work with different environments?
There are several possible approaches. Here are a couple:
Embed the current environment name in your external config file name:
grails.config.locations = [
"classpath:app-${grails.util.Environment.current.name}-config.properties"]
This will cause app-development-config.properties to be loaded in dev mode, app-test-config.properties in test, etc.
Use the .groovy config format instead of .properties. With a .groovy config file, you can use the environment { ... } block.